Skip to content

Commit 2f0a169

Browse files
committed
Reland "[Driver] Support multi /guard: options"
Fixes unexpected warning. Differential Revision: https://reviews.llvm.org/D150645
1 parent c2cec8a commit 2f0a169

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
@@ -7876,7 +7876,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
78767876
if (Args.hasArg(options::OPT__SLASH_kernel))
78777877
CmdArgs.push_back("-fms-kernel");
78787878

7879-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
7879+
for (const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
78807880
StringRef GuardArgs = A->getValue();
78817881
// The only valid options are "cf", "cf,nochecks", "cf-", "ehcont" and
78827882
// "ehcont-".
@@ -7895,6 +7895,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
78957895
} else {
78967896
D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
78977897
}
7898+
A->claim();
78987899
}
78997900
}
79007901

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)