[clang] [Driver][OpenMP] Fix OpenMP target-toolchain-option parser (PR #115375)
Jefferson Le Quellec via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 2 07:32:51 PST 2024
https://github.com/jle-quel updated https://github.com/llvm/llvm-project/pull/115375
>From b85cc64cee1ac22f27c648ca8d892b40804f6d98 Mon Sep 17 00:00:00 2001
From: Jefferson Le Quellec <jefferson.lequellec at codeplay.com>
Date: Thu, 7 Nov 2024 22:38:26 +0100
Subject: [PATCH 1/2] Fix OpenMP target-toolchain-option parser
---
clang/lib/Driver/Driver.cpp | 6 ++++++
clang/lib/Driver/ToolChain.cpp | 6 ++++--
clang/test/Driver/openmp-offload.c | 10 ++++++++--
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 93e85f7dffe35a..a7e985195a3051 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4528,7 +4528,13 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
ToolChain::getOpenMPTriple(Arg->getValue(0)) == TC->getTriple()) {
Arg->claim();
unsigned Index = Args.getBaseArgs().MakeIndex(Arg->getValue(1));
+ unsigned Prev = Index;
ExtractedArg = getOpts().ParseOneArg(Args, Index);
+ if (!ExtractedArg || Index > Prev + 1) {
+ TC->getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
+ << Arg->getAsString(Args);
+ continue;
+ }
Arg = ExtractedArg.get();
}
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 646dbc0faf5a9f..188d2dc7e03e25 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1598,8 +1598,10 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
Prev = Index;
std::unique_ptr<Arg> XOpenMPTargetArg(Opts.ParseOneArg(Args, Index));
if (!XOpenMPTargetArg || Index > Prev + 1) {
- getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
- << A->getAsString(Args);
+ if (!A->isClaimed()) {
+ getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
+ << A->getAsString(Args);
+ }
continue;
}
if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
diff --git a/clang/test/Driver/openmp-offload.c b/clang/test/Driver/openmp-offload.c
index eaed0d66df75cb..8c787cbc695335 100644
--- a/clang/test/Driver/openmp-offload.c
+++ b/clang/test/Driver/openmp-offload.c
@@ -84,9 +84,15 @@
/// Check -Xopenmp-target triggers error when an option requiring arguments is passed to it.
// RUN: not %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR %s
+// RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR_0 %s
-// CHK-FOPENMP-TARGET-NESTED-ERROR: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target -Xopenmp-target', options requiring arguments are unsupported
+// CHK-FOPENMP-TARGET-NESTED-ERROR_0: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target -Xopenmp-target', options requiring arguments are unsupported
+
+/// Check -Xopenmp-target= triggers error when an option requiring arguments is passed to it.
+// RUN: not %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target=powerpc64le-ibm-linux-gnu -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR_1 %s
+
+// CHK-FOPENMP-TARGET-NESTED-ERROR_1: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target=powerpc64le-ibm-linux-gnu -Xopenmp-target', options requiring arguments are unsupported
/// ###########################################################################
>From 6d897f13c237ad174680973751c272c1b459487f Mon Sep 17 00:00:00 2001
From: Jefferson Le Quellec <jefferson.lequellec at codeplay.com>
Date: Mon, 2 Dec 2024 16:32:32 +0100
Subject: [PATCH 2/2] Update tests to omit the string before 'error'
---
clang/test/Driver/openmp-offload.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/Driver/openmp-offload.c b/clang/test/Driver/openmp-offload.c
index 8c787cbc695335..caedc223a5c76f 100644
--- a/clang/test/Driver/openmp-offload.c
+++ b/clang/test/Driver/openmp-offload.c
@@ -86,13 +86,13 @@
// RUN: not %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR_0 %s
-// CHK-FOPENMP-TARGET-NESTED-ERROR_0: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target -Xopenmp-target', options requiring arguments are unsupported
+// CHK-FOPENMP-TARGET-NESTED-ERROR_0: error: invalid -Xopenmp-target argument: '-Xopenmp-target -Xopenmp-target', options requiring arguments are unsupported
/// Check -Xopenmp-target= triggers error when an option requiring arguments is passed to it.
// RUN: not %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target=powerpc64le-ibm-linux-gnu -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR_1 %s
-// CHK-FOPENMP-TARGET-NESTED-ERROR_1: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target=powerpc64le-ibm-linux-gnu -Xopenmp-target', options requiring arguments are unsupported
+// CHK-FOPENMP-TARGET-NESTED-ERROR_1: error: invalid -Xopenmp-target argument: '-Xopenmp-target=powerpc64le-ibm-linux-gnu -Xopenmp-target', options requiring arguments are unsupported
/// ###########################################################################
More information about the cfe-commits
mailing list