[PATCH] D152061: [clang] fix TranslateXarchArgs to support -Xarch_device -O* Origin code: when passed -Xarch_device -O1, TranslateXarchArgs will parse -O1 as a CLFlag, which has flags NoXarchOption , and then report error. Now: TranslateXarchArgs parse -O1 as O_Group
Chenguang Qiu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 3 04:31:12 PDT 2023
chenguang created this revision.
Herald added a project: All.
chenguang requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152061
Files:
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/hip-options.hip
Index: clang/test/Driver/hip-options.hip
===================================================================
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -33,6 +33,11 @@
// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" {{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
// DEV-NOT: clang{{.*}} {{.*}} "-debug-info-kind={{.*}}"
+// RUN: %clang -### -Xarch_device -O1 --cuda-gpu-arch=gfx900 -v \
+// RUN: %s 2>&1 | FileCheck -check-prefix=DEV %s
+// DEV: "-cc1" {{.*}} "-O1" {{.*}}
+
+
// RUN: %clang -### -Xarch_host -g -nogpulib --cuda-gpu-arch=gfx900 \
// RUN: --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefix=HOST %s
// HOST-NOT: "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}"
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -1327,28 +1327,18 @@
unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(ValuePos));
unsigned Prev = Index;
- std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(Args, Index));
+ std::unique_ptr<llvm::opt::Arg> XarchArg(
+ Opts.ParseOneArg(Args, Index, 0, options::NoXarchOption));
// If the argument parsing failed or more than one argument was
// consumed, the -Xarch_ argument's parameter tried to consume
// extra arguments. Emit an error and ignore.
- //
- // We also want to disallow any options which would alter the
- // driver behavior; that isn't going to work in our model. We
- // use options::NoXarchOption to control this.
if (!XarchArg || Index > Prev + 1) {
getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args)
<< A->getAsString(Args);
return;
- } else if (XarchArg->getOption().hasFlag(options::NoXarchOption)) {
- auto &Diags = getDriver().getDiags();
- unsigned DiagID =
- Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "invalid Xarch argument: '%0', not all driver "
- "options can be forwared via Xarch argument");
- Diags.Report(DiagID) << A->getAsString(Args);
- return;
}
+
XarchArg->setBaseArg(A);
A = XarchArg.release();
if (!AllocatedArgs)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152061.528095.patch
Type: text/x-patch
Size: 2299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230603/40bd58bf/attachment.bin>
More information about the cfe-commits
mailing list