diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index a0f4329e36136b..e7007b34bc8f7e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4527,7 +4527,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 0d426a467e9a3b..9f174fbda398b5 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -1596,8 +1596,10 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs( Prev = Index; std::unique_ptr 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..caedc223a5c76f 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: 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: error: invalid -Xopenmp-target argument: '-Xopenmp-target=powerpc64le-ibm-linux-gnu -Xopenmp-target', options requiring arguments are unsupported /// ###########################################################################