-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[Driver] Move CommonArgs to a location visible by the Frontend Drivers #142800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no maintenace burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk. In some cases, the Language Drivers will accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way.
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-backend-risc-v Author: Cameron McInally (mcinally) ChangesThis patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. Patch is 33.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142800.diff 56 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h
similarity index 98%
rename from clang/lib/Driver/ToolChains/CommonArgs.h
rename to clang/include/clang/Driver/CommonArgs.h
index b5b9c1e66e380..048f2eab6887e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/include/clang/Driver/CommonArgs.h
@@ -270,6 +270,12 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
/// Enable -fslp-vectorize based on the optimization level selected.
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs);
+
+void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ bool isCompilerDriver);
+
} // end namespace tools
} // end namespace driver
} // end namespace clang
diff --git a/clang/lib/Driver/MultilibBuilder.cpp b/clang/lib/Driver/MultilibBuilder.cpp
index 8440a82f78bef..9d44d8681cf8a 100644
--- a/clang/lib/Driver/MultilibBuilder.cpp
+++ b/clang/lib/Driver/MultilibBuilder.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/MultilibBuilder.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ce302b308fd19..91a17b6c49fd7 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -11,13 +11,13 @@
#include "ToolChains/Arch/ARM.h"
#include "ToolChains/Arch/RISCV.h"
#include "ToolChains/Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "ToolChains/Flang.h"
#include "ToolChains/InterfaceStubs.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Job.h"
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index a1a94e37116ce..066b59305fe3f 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AIX.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index dfbe936d5a5d3..cf9c24f1e1cde 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "clang/Basic/TargetID.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index f1529f857eef8..b0523a7f4e40e 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AVR.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index eaae9f876e3ad..ea906d2e2acfc 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AArch64.h"
-#include "../CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index a35f8276737ff..3318e498a74f9 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -8,8 +8,8 @@
#include "LoongArch.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/TargetParser/Host.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 0d847587e8664..8787c8276721c 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Mips.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index afa86230085ec..361a68a892a8f 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "PPC.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index d0b620980bcef..baa2c8c0bcfb2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -8,7 +8,7 @@
#include "RISCV.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 6bf2302d3bd99..d8168ed15febd 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -8,8 +8,8 @@
#include "BareMetal.h"
-#include "CommonArgs.h"
#include "Gnu.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/InputInfo.h"
#include "Arch/ARM.h"
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index e944cba0eb23c..e4db3307ee3aa 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CSKYToolChain.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 13842b8cc2870..bb3baa7cec4c0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -14,7 +14,6 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "Hexagon.h"
#include "PS4CPU.h"
#include "clang/Basic/CLWarnings.h"
@@ -26,6 +25,7 @@
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
@@ -264,27 +264,6 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
OutStrings.push_back(Args.MakeArgString(Out));
}
-/// The -mprefer-vector-width option accepts either a positive integer
-/// or the string "none".
-static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args,
- ArgStringList &CmdArgs) {
- Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
- if (!A)
- return;
-
- StringRef Value = A->getValue();
- if (Value == "none") {
- CmdArgs.push_back("-mprefer-vector-width=none");
- } else {
- unsigned Width;
- if (Value.getAsInteger(10, Width)) {
- D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
- return;
- }
- CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + Value));
- }
-}
-
static bool
shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
const llvm::Triple &Triple) {
@@ -7607,7 +7586,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
handleVectorizeLoopsArgs(Args, CmdArgs);
handleVectorizeSLPArgs(Args, CmdArgs);
- ParseMPreferVectorWidth(D, Args, CmdArgs);
+ ParseMPreferVectorWidthOption(D.getDiags(), Args, CmdArgs,
+ /*isCompilerDriver=*/true);
Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
Args.AddLastArg(CmdArgs,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 937ee09cac7cc..d927fc6d8b54b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "Arch/AArch64.h"
#include "Arch/ARM.h"
#include "Arch/CSKY.h"
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
options::OPT_fno_loop_interchange, EnableInterchange))
CmdArgs.push_back("-floop-interchange");
}
+
+void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ ArgStringList &CmdArgs,
+ bool isCompilerDriver) {
+ // If this was invoked by the Compiler Driver, we pass through the option
+ // as-is. Otherwise, if this is the Frontend Driver, we want just the value.
+ StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : "";
+
+ Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
+ if (!A)
+ return;
+
+ StringRef Value = A->getValue();
+ unsigned Width;
+
+ // Only "none" and Integer values are accepted by
+ // -mprefer-vector-width=<value>.
+ if (Value != "none" && Value.getAsInteger(10, Width)) {
+ Diags.Report(clang::diag::err_drv_invalid_value)
+ << A->getOption().getName() << Value;
+ return;
+ }
+
+ CmdArgs.push_back(Args.MakeArgString(Out + Value));
+ return;
+}
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8..51c892fc91718 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CrossWindows.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 073861dade4f7..a91e4de41c8da 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "Cuda.h"
-#include "CommonArgs.h"
#include "clang/Basic/Cuda.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/Driver.h"
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp
index f0e90deee98b3..d9c16347daa34 100644
--- a/clang/lib/Driver/ToolChains/Cygwin.cpp
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Cygwin.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0be7180098359..81e613cf7cdc7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -8,10 +8,10 @@
#include "Darwin.h"
#include "Arch/ARM.h"
-#include "CommonArgs.h"
#include "clang/Basic/AlignedAllocation.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 38a29ae49e8d9..524f5f2ff391e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "DragonFly.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index dcc46469df3e9..e0a366bfb9225 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -8,9 +8,9 @@
#include "Flang.h"
#include "Arch/RISCV.h"
-#include "CommonArgs.h"
#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Options.h"
#include "llvm/Frontend/Debug/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index ccf6987a2ea65..b17b76233ad30 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -10,8 +10,8 @@
#include "Arch/ARM.h"
#include "Arch/Mips.h"
#include "Arch/Sparc.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 910db1dde0d18..1c165bbfe84f5 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Fuchsia.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index e42cd0f97cb49..9c68c5c6de2b2 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -15,8 +15,8 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index fc067e9052275..a8f2b09b1b20f 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -8,10 +8,10 @@
#include "HIPAMD.h"
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
#include "SPIRV.h"
#include "clang/Basic/Cuda.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 02ec36df273af..ec29c62976e10 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "HIPSPV.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 8a3dd494f3b4f..cb061ffede234 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HIPUtility.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringExtras.h"
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index eb8f6881bffc7..dcc51e182924c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HLSL.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Job.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp
index 5d0d8b7f5024c..dd6ada8f56972 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Haiku.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/SanitizerArgs.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index bed8de94130c5..9f8b676fc7dc2 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 0bc114b90ffc0..a22a8face1797 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Hurd.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
index 05a13db8d0cff..59a6742c406c2 100644
--- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
+++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "InterfaceStubs.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Linux....
[truncated]
|
@llvm/pr-subscribers-backend-systemz Author: Cameron McInally (mcinally) ChangesThis patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. Patch is 33.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142800.diff 56 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h
similarity index 98%
rename from clang/lib/Driver/ToolChains/CommonArgs.h
rename to clang/include/clang/Driver/CommonArgs.h
index b5b9c1e66e380..048f2eab6887e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/include/clang/Driver/CommonArgs.h
@@ -270,6 +270,12 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
/// Enable -fslp-vectorize based on the optimization level selected.
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs);
+
+void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ bool isCompilerDriver);
+
} // end namespace tools
} // end namespace driver
} // end namespace clang
diff --git a/clang/lib/Driver/MultilibBuilder.cpp b/clang/lib/Driver/MultilibBuilder.cpp
index 8440a82f78bef..9d44d8681cf8a 100644
--- a/clang/lib/Driver/MultilibBuilder.cpp
+++ b/clang/lib/Driver/MultilibBuilder.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/MultilibBuilder.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ce302b308fd19..91a17b6c49fd7 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -11,13 +11,13 @@
#include "ToolChains/Arch/ARM.h"
#include "ToolChains/Arch/RISCV.h"
#include "ToolChains/Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "ToolChains/Flang.h"
#include "ToolChains/InterfaceStubs.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Job.h"
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index a1a94e37116ce..066b59305fe3f 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AIX.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index dfbe936d5a5d3..cf9c24f1e1cde 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "clang/Basic/TargetID.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index f1529f857eef8..b0523a7f4e40e 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AVR.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index eaae9f876e3ad..ea906d2e2acfc 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AArch64.h"
-#include "../CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index a35f8276737ff..3318e498a74f9 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -8,8 +8,8 @@
#include "LoongArch.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/TargetParser/Host.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 0d847587e8664..8787c8276721c 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Mips.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index afa86230085ec..361a68a892a8f 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "PPC.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index d0b620980bcef..baa2c8c0bcfb2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -8,7 +8,7 @@
#include "RISCV.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 6bf2302d3bd99..d8168ed15febd 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -8,8 +8,8 @@
#include "BareMetal.h"
-#include "CommonArgs.h"
#include "Gnu.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/InputInfo.h"
#include "Arch/ARM.h"
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index e944cba0eb23c..e4db3307ee3aa 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CSKYToolChain.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 13842b8cc2870..bb3baa7cec4c0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -14,7 +14,6 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "Hexagon.h"
#include "PS4CPU.h"
#include "clang/Basic/CLWarnings.h"
@@ -26,6 +25,7 @@
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
@@ -264,27 +264,6 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
OutStrings.push_back(Args.MakeArgString(Out));
}
-/// The -mprefer-vector-width option accepts either a positive integer
-/// or the string "none".
-static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args,
- ArgStringList &CmdArgs) {
- Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
- if (!A)
- return;
-
- StringRef Value = A->getValue();
- if (Value == "none") {
- CmdArgs.push_back("-mprefer-vector-width=none");
- } else {
- unsigned Width;
- if (Value.getAsInteger(10, Width)) {
- D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
- return;
- }
- CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + Value));
- }
-}
-
static bool
shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
const llvm::Triple &Triple) {
@@ -7607,7 +7586,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
handleVectorizeLoopsArgs(Args, CmdArgs);
handleVectorizeSLPArgs(Args, CmdArgs);
- ParseMPreferVectorWidth(D, Args, CmdArgs);
+ ParseMPreferVectorWidthOption(D.getDiags(), Args, CmdArgs,
+ /*isCompilerDriver=*/true);
Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
Args.AddLastArg(CmdArgs,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 937ee09cac7cc..d927fc6d8b54b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "Arch/AArch64.h"
#include "Arch/ARM.h"
#include "Arch/CSKY.h"
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
options::OPT_fno_loop_interchange, EnableInterchange))
CmdArgs.push_back("-floop-interchange");
}
+
+void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ ArgStringList &CmdArgs,
+ bool isCompilerDriver) {
+ // If this was invoked by the Compiler Driver, we pass through the option
+ // as-is. Otherwise, if this is the Frontend Driver, we want just the value.
+ StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : "";
+
+ Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
+ if (!A)
+ return;
+
+ StringRef Value = A->getValue();
+ unsigned Width;
+
+ // Only "none" and Integer values are accepted by
+ // -mprefer-vector-width=<value>.
+ if (Value != "none" && Value.getAsInteger(10, Width)) {
+ Diags.Report(clang::diag::err_drv_invalid_value)
+ << A->getOption().getName() << Value;
+ return;
+ }
+
+ CmdArgs.push_back(Args.MakeArgString(Out + Value));
+ return;
+}
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8..51c892fc91718 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CrossWindows.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 073861dade4f7..a91e4de41c8da 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "Cuda.h"
-#include "CommonArgs.h"
#include "clang/Basic/Cuda.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/Driver.h"
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp
index f0e90deee98b3..d9c16347daa34 100644
--- a/clang/lib/Driver/ToolChains/Cygwin.cpp
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Cygwin.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0be7180098359..81e613cf7cdc7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -8,10 +8,10 @@
#include "Darwin.h"
#include "Arch/ARM.h"
-#include "CommonArgs.h"
#include "clang/Basic/AlignedAllocation.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 38a29ae49e8d9..524f5f2ff391e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "DragonFly.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index dcc46469df3e9..e0a366bfb9225 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -8,9 +8,9 @@
#include "Flang.h"
#include "Arch/RISCV.h"
-#include "CommonArgs.h"
#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Options.h"
#include "llvm/Frontend/Debug/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index ccf6987a2ea65..b17b76233ad30 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -10,8 +10,8 @@
#include "Arch/ARM.h"
#include "Arch/Mips.h"
#include "Arch/Sparc.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 910db1dde0d18..1c165bbfe84f5 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Fuchsia.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index e42cd0f97cb49..9c68c5c6de2b2 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -15,8 +15,8 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index fc067e9052275..a8f2b09b1b20f 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -8,10 +8,10 @@
#include "HIPAMD.h"
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
#include "SPIRV.h"
#include "clang/Basic/Cuda.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 02ec36df273af..ec29c62976e10 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "HIPSPV.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 8a3dd494f3b4f..cb061ffede234 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HIPUtility.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringExtras.h"
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index eb8f6881bffc7..dcc51e182924c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HLSL.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Job.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp
index 5d0d8b7f5024c..dd6ada8f56972 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Haiku.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/SanitizerArgs.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index bed8de94130c5..9f8b676fc7dc2 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 0bc114b90ffc0..a22a8face1797 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Hurd.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
index 05a13db8d0cff..59a6742c406c2 100644
--- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
+++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "InterfaceStubs.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Linux....
[truncated]
|
@llvm/pr-subscribers-clang-driver Author: Cameron McInally (mcinally) ChangesThis patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. Patch is 33.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142800.diff 56 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h
similarity index 98%
rename from clang/lib/Driver/ToolChains/CommonArgs.h
rename to clang/include/clang/Driver/CommonArgs.h
index b5b9c1e66e380..048f2eab6887e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/include/clang/Driver/CommonArgs.h
@@ -270,6 +270,12 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
/// Enable -fslp-vectorize based on the optimization level selected.
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs);
+
+void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ bool isCompilerDriver);
+
} // end namespace tools
} // end namespace driver
} // end namespace clang
diff --git a/clang/lib/Driver/MultilibBuilder.cpp b/clang/lib/Driver/MultilibBuilder.cpp
index 8440a82f78bef..9d44d8681cf8a 100644
--- a/clang/lib/Driver/MultilibBuilder.cpp
+++ b/clang/lib/Driver/MultilibBuilder.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/MultilibBuilder.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ce302b308fd19..91a17b6c49fd7 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -11,13 +11,13 @@
#include "ToolChains/Arch/ARM.h"
#include "ToolChains/Arch/RISCV.h"
#include "ToolChains/Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "ToolChains/Flang.h"
#include "ToolChains/InterfaceStubs.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Job.h"
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index a1a94e37116ce..066b59305fe3f 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AIX.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index dfbe936d5a5d3..cf9c24f1e1cde 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "clang/Basic/TargetID.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index f1529f857eef8..b0523a7f4e40e 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AVR.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index eaae9f876e3ad..ea906d2e2acfc 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AArch64.h"
-#include "../CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index a35f8276737ff..3318e498a74f9 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -8,8 +8,8 @@
#include "LoongArch.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/TargetParser/Host.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 0d847587e8664..8787c8276721c 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Mips.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index afa86230085ec..361a68a892a8f 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "PPC.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index d0b620980bcef..baa2c8c0bcfb2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -8,7 +8,7 @@
#include "RISCV.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 6bf2302d3bd99..d8168ed15febd 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -8,8 +8,8 @@
#include "BareMetal.h"
-#include "CommonArgs.h"
#include "Gnu.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/InputInfo.h"
#include "Arch/ARM.h"
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index e944cba0eb23c..e4db3307ee3aa 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CSKYToolChain.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 13842b8cc2870..bb3baa7cec4c0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -14,7 +14,6 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "Hexagon.h"
#include "PS4CPU.h"
#include "clang/Basic/CLWarnings.h"
@@ -26,6 +25,7 @@
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
@@ -264,27 +264,6 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
OutStrings.push_back(Args.MakeArgString(Out));
}
-/// The -mprefer-vector-width option accepts either a positive integer
-/// or the string "none".
-static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args,
- ArgStringList &CmdArgs) {
- Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
- if (!A)
- return;
-
- StringRef Value = A->getValue();
- if (Value == "none") {
- CmdArgs.push_back("-mprefer-vector-width=none");
- } else {
- unsigned Width;
- if (Value.getAsInteger(10, Width)) {
- D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
- return;
- }
- CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + Value));
- }
-}
-
static bool
shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
const llvm::Triple &Triple) {
@@ -7607,7 +7586,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
handleVectorizeLoopsArgs(Args, CmdArgs);
handleVectorizeSLPArgs(Args, CmdArgs);
- ParseMPreferVectorWidth(D, Args, CmdArgs);
+ ParseMPreferVectorWidthOption(D.getDiags(), Args, CmdArgs,
+ /*isCompilerDriver=*/true);
Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
Args.AddLastArg(CmdArgs,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 937ee09cac7cc..d927fc6d8b54b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "Arch/AArch64.h"
#include "Arch/ARM.h"
#include "Arch/CSKY.h"
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
options::OPT_fno_loop_interchange, EnableInterchange))
CmdArgs.push_back("-floop-interchange");
}
+
+void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ ArgStringList &CmdArgs,
+ bool isCompilerDriver) {
+ // If this was invoked by the Compiler Driver, we pass through the option
+ // as-is. Otherwise, if this is the Frontend Driver, we want just the value.
+ StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : "";
+
+ Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
+ if (!A)
+ return;
+
+ StringRef Value = A->getValue();
+ unsigned Width;
+
+ // Only "none" and Integer values are accepted by
+ // -mprefer-vector-width=<value>.
+ if (Value != "none" && Value.getAsInteger(10, Width)) {
+ Diags.Report(clang::diag::err_drv_invalid_value)
+ << A->getOption().getName() << Value;
+ return;
+ }
+
+ CmdArgs.push_back(Args.MakeArgString(Out + Value));
+ return;
+}
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8..51c892fc91718 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CrossWindows.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 073861dade4f7..a91e4de41c8da 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "Cuda.h"
-#include "CommonArgs.h"
#include "clang/Basic/Cuda.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/Driver.h"
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp
index f0e90deee98b3..d9c16347daa34 100644
--- a/clang/lib/Driver/ToolChains/Cygwin.cpp
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Cygwin.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0be7180098359..81e613cf7cdc7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -8,10 +8,10 @@
#include "Darwin.h"
#include "Arch/ARM.h"
-#include "CommonArgs.h"
#include "clang/Basic/AlignedAllocation.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 38a29ae49e8d9..524f5f2ff391e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "DragonFly.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index dcc46469df3e9..e0a366bfb9225 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -8,9 +8,9 @@
#include "Flang.h"
#include "Arch/RISCV.h"
-#include "CommonArgs.h"
#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Options.h"
#include "llvm/Frontend/Debug/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index ccf6987a2ea65..b17b76233ad30 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -10,8 +10,8 @@
#include "Arch/ARM.h"
#include "Arch/Mips.h"
#include "Arch/Sparc.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 910db1dde0d18..1c165bbfe84f5 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Fuchsia.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index e42cd0f97cb49..9c68c5c6de2b2 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -15,8 +15,8 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index fc067e9052275..a8f2b09b1b20f 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -8,10 +8,10 @@
#include "HIPAMD.h"
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
#include "SPIRV.h"
#include "clang/Basic/Cuda.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 02ec36df273af..ec29c62976e10 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "HIPSPV.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 8a3dd494f3b4f..cb061ffede234 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HIPUtility.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringExtras.h"
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index eb8f6881bffc7..dcc51e182924c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HLSL.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Job.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp
index 5d0d8b7f5024c..dd6ada8f56972 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Haiku.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/SanitizerArgs.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index bed8de94130c5..9f8b676fc7dc2 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 0bc114b90ffc0..a22a8face1797 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Hurd.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
index 05a13db8d0cff..59a6742c406c2 100644
--- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
+++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "InterfaceStubs.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Linux....
[truncated]
|
@llvm/pr-subscribers-flang-driver Author: Cameron McInally (mcinally) ChangesThis patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. Patch is 33.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142800.diff 56 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/include/clang/Driver/CommonArgs.h
similarity index 98%
rename from clang/lib/Driver/ToolChains/CommonArgs.h
rename to clang/include/clang/Driver/CommonArgs.h
index b5b9c1e66e380..048f2eab6887e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/include/clang/Driver/CommonArgs.h
@@ -270,6 +270,12 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
/// Enable -fslp-vectorize based on the optimization level selected.
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs);
+
+void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ bool isCompilerDriver);
+
} // end namespace tools
} // end namespace driver
} // end namespace clang
diff --git a/clang/lib/Driver/MultilibBuilder.cpp b/clang/lib/Driver/MultilibBuilder.cpp
index 8440a82f78bef..9d44d8681cf8a 100644
--- a/clang/lib/Driver/MultilibBuilder.cpp
+++ b/clang/lib/Driver/MultilibBuilder.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/MultilibBuilder.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ce302b308fd19..91a17b6c49fd7 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -11,13 +11,13 @@
#include "ToolChains/Arch/ARM.h"
#include "ToolChains/Arch/RISCV.h"
#include "ToolChains/Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "ToolChains/Flang.h"
#include "ToolChains/InterfaceStubs.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Job.h"
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index a1a94e37116ce..066b59305fe3f 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AIX.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index dfbe936d5a5d3..cf9c24f1e1cde 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "clang/Basic/TargetID.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index f1529f857eef8..b0523a7f4e40e 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AVR.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index eaae9f876e3ad..ea906d2e2acfc 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AArch64.h"
-#include "../CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index a35f8276737ff..3318e498a74f9 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -8,8 +8,8 @@
#include "LoongArch.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
#include "clang/Basic/DiagnosticDriver.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/TargetParser/Host.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 0d847587e8664..8787c8276721c 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Mips.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index afa86230085ec..361a68a892a8f 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "PPC.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index d0b620980bcef..baa2c8c0bcfb2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -8,7 +8,7 @@
#include "RISCV.h"
#include "../Clang.h"
-#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 6bf2302d3bd99..d8168ed15febd 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -8,8 +8,8 @@
#include "BareMetal.h"
-#include "CommonArgs.h"
#include "Gnu.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/InputInfo.h"
#include "Arch/ARM.h"
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index e944cba0eb23c..e4db3307ee3aa 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CSKYToolChain.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 13842b8cc2870..bb3baa7cec4c0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -14,7 +14,6 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "Hexagon.h"
#include "PS4CPU.h"
#include "clang/Basic/CLWarnings.h"
@@ -26,6 +25,7 @@
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
@@ -264,27 +264,6 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
OutStrings.push_back(Args.MakeArgString(Out));
}
-/// The -mprefer-vector-width option accepts either a positive integer
-/// or the string "none".
-static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args,
- ArgStringList &CmdArgs) {
- Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
- if (!A)
- return;
-
- StringRef Value = A->getValue();
- if (Value == "none") {
- CmdArgs.push_back("-mprefer-vector-width=none");
- } else {
- unsigned Width;
- if (Value.getAsInteger(10, Width)) {
- D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
- return;
- }
- CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + Value));
- }
-}
-
static bool
shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
const llvm::Triple &Triple) {
@@ -7607,7 +7586,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
handleVectorizeLoopsArgs(Args, CmdArgs);
handleVectorizeSLPArgs(Args, CmdArgs);
- ParseMPreferVectorWidth(D, Args, CmdArgs);
+ ParseMPreferVectorWidthOption(D.getDiags(), Args, CmdArgs,
+ /*isCompilerDriver=*/true);
Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
Args.AddLastArg(CmdArgs,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 937ee09cac7cc..d927fc6d8b54b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "Arch/AArch64.h"
#include "Arch/ARM.h"
#include "Arch/CSKY.h"
@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
options::OPT_fno_loop_interchange, EnableInterchange))
CmdArgs.push_back("-floop-interchange");
}
+
+void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+ const llvm::opt::ArgList &Args,
+ ArgStringList &CmdArgs,
+ bool isCompilerDriver) {
+ // If this was invoked by the Compiler Driver, we pass through the option
+ // as-is. Otherwise, if this is the Frontend Driver, we want just the value.
+ StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : "";
+
+ Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
+ if (!A)
+ return;
+
+ StringRef Value = A->getValue();
+ unsigned Width;
+
+ // Only "none" and Integer values are accepted by
+ // -mprefer-vector-width=<value>.
+ if (Value != "none" && Value.getAsInteger(10, Width)) {
+ Diags.Report(clang::diag::err_drv_invalid_value)
+ << A->getOption().getName() << Value;
+ return;
+ }
+
+ CmdArgs.push_back(Args.MakeArgString(Out + Value));
+ return;
+}
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8..51c892fc91718 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CrossWindows.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 073861dade4f7..a91e4de41c8da 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "Cuda.h"
-#include "CommonArgs.h"
#include "clang/Basic/Cuda.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/Driver.h"
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp
index f0e90deee98b3..d9c16347daa34 100644
--- a/clang/lib/Driver/ToolChains/Cygwin.cpp
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Cygwin.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0be7180098359..81e613cf7cdc7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -8,10 +8,10 @@
#include "Darwin.h"
#include "Arch/ARM.h"
-#include "CommonArgs.h"
#include "clang/Basic/AlignedAllocation.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 38a29ae49e8d9..524f5f2ff391e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "DragonFly.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index dcc46469df3e9..e0a366bfb9225 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -8,9 +8,9 @@
#include "Flang.h"
#include "Arch/RISCV.h"
-#include "CommonArgs.h"
#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Options.h"
#include "llvm/Frontend/Debug/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index ccf6987a2ea65..b17b76233ad30 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -10,8 +10,8 @@
#include "Arch/ARM.h"
#include "Arch/Mips.h"
#include "Arch/Sparc.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 910db1dde0d18..1c165bbfe84f5 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Fuchsia.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index e42cd0f97cb49..9c68c5c6de2b2 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -15,8 +15,8 @@
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/MultilibBuilder.h"
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index fc067e9052275..a8f2b09b1b20f 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -8,10 +8,10 @@
#include "HIPAMD.h"
#include "AMDGPU.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
#include "SPIRV.h"
#include "clang/Basic/Cuda.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 02ec36df273af..ec29c62976e10 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "HIPSPV.h"
-#include "CommonArgs.h"
#include "HIPUtility.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 8a3dd494f3b4f..cb061ffede234 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HIPUtility.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringExtras.h"
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index eb8f6881bffc7..dcc51e182924c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "HLSL.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Job.h"
#include "llvm/ADT/StringSwitch.h"
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp
index 5d0d8b7f5024c..dd6ada8f56972 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Haiku.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/SanitizerArgs.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index bed8de94130c5..9f8b676fc7dc2 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Hexagon.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/InputInfo.h"
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 0bc114b90ffc0..a22a8face1797 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "Hurd.h"
-#include "CommonArgs.h"
#include "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
index 05a13db8d0cff..59a6742c406c2 100644
--- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
+++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "InterfaceStubs.h"
-#include "CommonArgs.h"
+#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Compilation.h"
#include "llvm/Support/Path.h"
diff --git a/clang/lib/Driver/ToolChains/Linux....
[truncated]
|
@@ -270,6 +270,12 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args, | |||
/// Enable -fslp-vectorize based on the optimization level selected. | |||
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args, | |||
llvm::opt::ArgStringList &CmdArgs); | |||
|
|||
void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the handling of the mprefer-vector-width option intended to be part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was, for illustrative purposes. I have no problem removing it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let's leave it in for now. Since this is reorganizing the code in clang, we should wait for the clang developers to weigh in on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Cameron! It looks good to me with one minor comment.
return; | ||
} | ||
|
||
CmdArgs.push_back(Args.MakeArgString(Out + Value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe the function should just return Value
, and then the callers may process it as needed (e.g. prepend it with -mprefer-vector-width=
and push it into the args list) This behavior will align with the name of the function a little better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this function behaves is consistent with the way options are handled in this part of the code. We could consider renaming the function handleMPreferVectorWidthOptions
if the word "Parse" suggests that it will return something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this aligns with how other functions work. At the same time, it seems awkward to me that we push just the value into the args-list, when the caller is a frontend driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awkward. I was hoping someone with more C++ expertise would have a trick to streamline it.
I chose this solution so that the Compiler Driver side would be as undisturbed as possible.
I also don't feel strongly that it needs to change for an initial implementation. It's something we could build out in the future as we learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function could take an ArgStringList*
, only push Out + Value
if it is provided, and always return Value as a StringRef.
That way the compiler driver can pass the list and ignore the result and the frontend can just use the result.
Not sure if it would works with all options, I am not familiar with the drivers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function could take an ArgStringList*, only push Out + Value if it is provided, and always return Value as a StringRef.
That would work. It would disturb the Compiler Driver a bit to avoid warnings. We'd need to explicitly discard the results when unwanted. E.g.:
(void)ParseMPreferVectorWidthOption(...);
I wonder if we could come up with a Frontend Driver mechanism to discard everything up to and including the =
. Then we'd just need to wrap the parsing/handling call in that mechanism.
Not sure if it would works with all options, I am not familiar with the drivers.
Same. I suggest that we delay this decision until there's a better view of the entire problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh! Sorry, I somehow missed the real issue here. Sorry, it must have been one of those days.
That would work. It would disturb the Compiler Driver a bit to avoid warnings. We'd need to explicitly discard the results when unwanted. E.g.:
(void)ParseMPreferVectorWidthOption(...);
Just to clarify, by warnings you mean warnings when building clang
itself, right?
Same. I suggest that we delay this decision until there's a better view of the entire problem.
Is the real issue here that we need to validate the argument values? It is a fairly common pattern in, e.g. clang/lib/Frontend/CompilerInvocation.cpp
to look at the ArgList
and parse the arguments there. It may be better to share the argument validation and return, say, an optional value with the correctly parsed value if it exists. How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, by warnings you mean warnings when building clang itself, right?
Correct. The unused result would be a warning.
Is the real issue here that we need to validate the argument values? It is a fairly common pattern in, e.g. clang/lib/Frontend/CompilerInvocation.cpp to look at the ArgList and parse the arguments there.
Yes, that's what we're trying to avoid. Both Frontend/CompilerInvocation.cpp
and Driver/FC]lang.cpp
could do verification, but we don't want to have the same/similar code in both places. This patch would let Frontend/CompilerInvocation.cpp
and Driver/[FC]lang.cpp
share the same parsing/handling functions.
It may be better to share the argument validation and return, say, an optional value with the correctly parsed value if it exists. How does that sound?
I like that!!
I'll wait to see if there are other ideas before updating the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I take that back. This solution is pretty slick. Sharing an update now...
Just FYI, I had to rebase my PRs to resolve the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for removing the duplication here!
Update initial patch to use std::optional return values for the parsing functions. This is a more elegant way of returning just the Values to the Frontend Drivers.
✅ With the latest revision this PR passed the C/C++ code formatter. |
return std::nullopt; | ||
|
||
StringRef Value = A->getValue(); | ||
unsigned Width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add __attribute((uninitialized))
since this left uninitialized on purpose and is use solely for getAsInteger below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we can't add this. The MSVC build is failing since __attribute((uninitialized))
isn't supported there. I'll remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems better instead of removing it to add it as a macro in llvm/include/llvm/Support/Compiler.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
Co-authored-by: Shafik Yaghmour <[email protected]>
return std::nullopt; | ||
} | ||
|
||
CmdArgs.push_back(Args.MakeArgString(Out + Value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better to always return just the value here, instead of option + value
. We can still add to CmdArgs
if isCompilerDriver=true
. That way, we don't have to make the change in the caller-side. The caller can just ignore the return value. In the case where isCompilerDriver=false
, we can initialize the options object with the return value as appropriate. Does that sound reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative would be to not add to CmdArgs
here, but to do it in the caller instead. I think that is ok too. It would be a bit of a departure from the way the rest of the code works, but it feels like a more "natural" way of handling this. The rest of the code could, gradually, be made more consistent with this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative would be to not add to CmdArgs here, but to do it in the caller instead.
That's a good point as well. There are plenty of CmdArgs.push_back(...)
's in clang/lib/Driver/ToolChains/Clang.cpp
already, so it wouldn't be awkward.
Let me code that up and we can see if we like it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a new patch. I like it a lot. See what you think...
We were able to get rid of isCompilerDriver
and the clang/lib/Driver/ToolChains/Clang.cpp
change doesn't look awkward at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
))) this is what I suggested 2 days ago
Thank you, Cameron!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
))) this is what I suggested 2 days ago
Yes. As I said 1 day ago, I am not sure how I missed the obvious the first time around. :-)
@@ -270,6 +270,11 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args, | |||
/// Enable -fslp-vectorize based on the optimization level selected. | |||
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args, | |||
llvm::opt::ArgStringList &CmdArgs); | |||
|
|||
std::optional<StringRef> ParseMPreferVectorWidthOption( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a docstring for this function
This patch reworks ParseMPreferVectorWidthOption(...) to only return the Value StringRef. It will now be the responsibility of the caller to handle the Value appropriately. This allows more flexibily and makes ParseMPreferVectorWidthOption(...) useful in different contexts. Also, add a docstring for this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, Cameron.
Could you take a look at the failing buildkite and see if it is something relevant? It seems to be a Windows build. Those are a bit flaky and a failure doesn't necessarily mean that there is a problem with the PR, but it's probably worth taking a look just in case.
Remove __attribute((uninitialized)) as it's not supported on Windows.
Thanks! It looks like |
It looks like we have a number of approvals and I haven't seen any objections yet. Should we go ahead with merging this in the current state? If so, I'll need help there since I don't have commit access yet. @tarunprabhu would you mind volunteering to mash the merge button again? |
I had 1 minor objection, see my concern on the |
Add LLVM_ATTRIBUTE_UNINITIALIZED to map to __attribute__((uninitialized)) when available.
Would it be simpler just to initialize the variable before use? I assume that the attribute is present to eliminate compiler warnings about uninitialized variables being passed by reference. I don't see the use of this anywhere else in the code base. Does adding that attribute really provide a great deal of meaningful context? |
It was easy enough to add. Seems like it would be useful in general too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this passes CI/goes green check, I think we're good to click the 'merge' button.
This is looking like a better option. Some CIs don't seem to pick up the macro. I'll do some investigating, but I'm not able to reproduce with my build. |
Missing 'Z'.
return ""; | ||
|
||
StringRef Value = A->getValue(); | ||
unsigned Width LLVM_ATTRIBUTE_UNINITIALIZED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but FWIW, there's C++ [[maybe_unused]]
that could possibly work here: https://en.cppreference.com/w/cpp/language/attributes/maybe_unused
All checks have passed, if someone wouldn't mind merging for me. Thanks in advance! |
llvm#142800) This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --------- Co-authored-by: Cameron McInally <[email protected]> Co-authored-by: Shafik Yaghmour <[email protected]>
llvm#142800) This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel. We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync. Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.: `clang -cc1 -mprefer-vector-width=junk test.c' With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way. --------- Co-authored-by: Cameron McInally <[email protected]> Co-authored-by: Shafik Yaghmour <[email protected]>
This patch moves the CommonArgs utilities into a location visible by the Frontend Drivers, so that the Frontend Drivers may share option parsing code with the Compiler Driver. This is useful when the Frontend Drivers would like to verify that their incoming options are well-formed and also not reinvent the option parsing wheel.
We already see code in the Clang/Flang Drivers that is parsing and verifying its incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with slightly different parsing code. It would be nice if the Frontend Drivers were not required to duplicate this Compiler Driver code. That way there is no/low maintenance burden on keeping all these parsing functions in sync.
Along those lines, the Frontend Drivers will now have a useful mechanism to verify their incoming options are well-formed. Currently, the Frontend Drivers trust that the Compiler Driver is not passing back junk in some cases. The Language Drivers may even accept junk with no error at all. E.g.:
`clang -cc1 -mprefer-vector-width=junk test.c'
With this patch, we'll now be able to tighten up incomming options to the Frontend drivers in a lightweight way.