Skip to content

Commit 8808a54

Browse files
authored
[NFC][clang] Move argument handling: Driver::BuildActions -> handleArguments (#142455)
This simply moves code for diagnosing misuse of arguments `/Fo`, `/Fa`, and `/o` from `Driver::BuildActions` into `Driver::handleArguments`, following the intention of 740f69b. This change better aligns with the roles of `BuildActions` and `handleArguments`.
1 parent 2622e6b commit 8808a54

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,39 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
42264226
const InputList &Inputs,
42274227
ActionList &Actions) const {
42284228

4229+
// Diagnose misuse of /Fo.
4230+
if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fo)) {
4231+
StringRef V = A->getValue();
4232+
if (Inputs.size() > 1 && !V.empty() &&
4233+
!llvm::sys::path::is_separator(V.back())) {
4234+
// Check whether /Fo tries to name an output file for multiple inputs.
4235+
Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
4236+
<< A->getSpelling() << V;
4237+
Args.eraseArg(options::OPT__SLASH_Fo);
4238+
}
4239+
}
4240+
4241+
// Diagnose misuse of /Fa.
4242+
if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fa)) {
4243+
StringRef V = A->getValue();
4244+
if (Inputs.size() > 1 && !V.empty() &&
4245+
!llvm::sys::path::is_separator(V.back())) {
4246+
// Check whether /Fa tries to name an asm file for multiple inputs.
4247+
Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
4248+
<< A->getSpelling() << V;
4249+
Args.eraseArg(options::OPT__SLASH_Fa);
4250+
}
4251+
}
4252+
4253+
// Diagnose misuse of /o.
4254+
if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) {
4255+
if (A->getValue()[0] == '\0') {
4256+
// It has to have a value.
4257+
Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1;
4258+
Args.eraseArg(options::OPT__SLASH_o);
4259+
}
4260+
}
4261+
42294262
// Ignore /Yc/Yu if both /Yc and /Yu passed but with different filenames.
42304263
Arg *YcArg = Args.getLastArg(options::OPT__SLASH_Yc);
42314264
Arg *YuArg = Args.getLastArg(options::OPT__SLASH_Yu);
@@ -4368,39 +4401,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43684401
return;
43694402
}
43704403

4371-
// Diagnose misuse of /Fo.
4372-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fo)) {
4373-
StringRef V = A->getValue();
4374-
if (Inputs.size() > 1 && !V.empty() &&
4375-
!llvm::sys::path::is_separator(V.back())) {
4376-
// Check whether /Fo tries to name an output file for multiple inputs.
4377-
Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
4378-
<< A->getSpelling() << V;
4379-
Args.eraseArg(options::OPT__SLASH_Fo);
4380-
}
4381-
}
4382-
4383-
// Diagnose misuse of /Fa.
4384-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fa)) {
4385-
StringRef V = A->getValue();
4386-
if (Inputs.size() > 1 && !V.empty() &&
4387-
!llvm::sys::path::is_separator(V.back())) {
4388-
// Check whether /Fa tries to name an asm file for multiple inputs.
4389-
Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
4390-
<< A->getSpelling() << V;
4391-
Args.eraseArg(options::OPT__SLASH_Fa);
4392-
}
4393-
}
4394-
4395-
// Diagnose misuse of /o.
4396-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) {
4397-
if (A->getValue()[0] == '\0') {
4398-
// It has to have a value.
4399-
Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1;
4400-
Args.eraseArg(options::OPT__SLASH_o);
4401-
}
4402-
}
4403-
44044404
handleArguments(C, Args, Inputs, Actions);
44054405

44064406
bool UseNewOffloadingDriver =

0 commit comments

Comments
 (0)