From: Phoebe Wang Date: Tue, 16 May 2023 15:39:05 +0000 (+0800) Subject: [Driver] Support multi /guard: options X-Git-Tag: upstream/17.0.6~8325 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b6f7e45a20990fdbc2b43dc08457fc79d53bd39;p=platform%2Fupstream%2Fllvm.git [Driver] Support multi /guard: options Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D150645 --- diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index f057e21..36fad70 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7865,7 +7865,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType, if (Args.hasArg(options::OPT__SLASH_kernel)) CmdArgs.push_back("-fms-kernel"); - if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) { + for (const Arg *A : Args.filtered(options::OPT__SLASH_guard)) { StringRef GuardArgs = A->getValue(); // The only valid options are "cf", "cf,nochecks", "cf-", "ehcont" and // "ehcont-". diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index b23d0aa..d803dda 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -227,7 +227,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); // Control Flow Guard checks - if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) { + for (const Arg *A : Args.filtered(options::OPT__SLASH_guard)) { StringRef GuardArgs = A->getValue(); if (GuardArgs.equals_insensitive("cf") || GuardArgs.equals_insensitive("cf,nochecks")) { diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index 12d7023..c7d7fae 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -647,6 +647,10 @@ // RUN: %clang_cl /guard:ehcont -### -- %s 2>&1 | FileCheck -check-prefix=EHCONTGUARD %s // EHCONTGUARD: -ehcontguard +// RUN: %clang_cl /guard:cf /guard:ehcont -### -- %s 2>&1 | FileCheck -check-prefix=BOTHGUARD %s +// BOTHGUARD: -cfguard +// BOTHGUARD-SAME: -ehcontguard + // RUN: %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s // CFGUARDINVALID: invalid value 'foo' in '/guard:'