Skip to content

Commit

Permalink
Reland "[Driver] Support multi /guard: options"
Browse files Browse the repository at this point in the history
Fixes unexpected warning.

Differential Revision: https://reviews.llvm.org/D150645
  • Loading branch information
phoebewang committed May 21, 2023
1 parent c2cec8a commit 2f0a169
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7876,7 +7876,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-".
Expand All @@ -7895,6 +7895,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
} else {
D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
}
A->claim();
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/cl-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,13 @@
// RUN: %clang_cl /guard:ehcont -### -- %s 2>&1 | FileCheck -check-prefix=EHCONTGUARD %s
// EHCONTGUARD: -ehcontguard

// RUN: %clang_cl /guard:cf /guard:ehcont -Wall -Wno-msvc-not-found -### -- %s 2>&1 | \
// RUN: FileCheck -check-prefix=BOTHGUARD %s --implicit-check-not=warning:
// BOTHGUARD: -cfguard
// BOTHGUARD-SAME: -ehcontguard
// BOTHGUARD: -guard:cf
// BOTHGUARD-SAME: -guard:ehcont

// RUN: %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s
// CFGUARDINVALID: invalid value 'foo' in '/guard:'

Expand Down

0 comments on commit 2f0a169

Please sign in to comment.