Skip to content

Commit 17ceb95

Browse files
phoebewangtstellar
authored andcommitted
Reland "[Driver] Support multi /guard: options"
Fixes unexpected warning. Differential Revision: https://reviews.llvm.org/D150645 (cherry picked from commit 2f0a169)
1 parent cd93216 commit 17ceb95

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7782,7 +7782,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
77827782
if (Args.hasArg(options::OPT__SLASH_kernel))
77837783
CmdArgs.push_back("-fms-kernel");
77847784

7785-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
7785+
for (const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
77867786
StringRef GuardArgs = A->getValue();
77877787
// The only valid options are "cf", "cf,nochecks", "cf-", "ehcont" and
77887788
// "ehcont-".
@@ -7801,6 +7801,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
78017801
} else {
78027802
D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
78037803
}
7804+
A->claim();
78047805
}
78057806
}
78067807

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
227227
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
228228

229229
// Control Flow Guard checks
230-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
230+
for (const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
231231
StringRef GuardArgs = A->getValue();
232232
if (GuardArgs.equals_insensitive("cf") ||
233233
GuardArgs.equals_insensitive("cf,nochecks")) {

clang/test/Driver/cl-options.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,13 @@
647647
// RUN: %clang_cl /guard:ehcont -### -- %s 2>&1 | FileCheck -check-prefix=EHCONTGUARD %s
648648
// EHCONTGUARD: -ehcontguard
649649

650+
// RUN: %clang_cl /guard:cf /guard:ehcont -Wall -Wno-msvc-not-found -### -- %s 2>&1 | \
651+
// RUN: FileCheck -check-prefix=BOTHGUARD %s --implicit-check-not=warning:
652+
// BOTHGUARD: -cfguard
653+
// BOTHGUARD-SAME: -ehcontguard
654+
// BOTHGUARD: -guard:cf
655+
// BOTHGUARD-SAME: -guard:ehcont
656+
650657
// RUN: %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s
651658
// CFGUARDINVALID: invalid value 'foo' in '/guard:'
652659

0 commit comments

Comments
 (0)