Skip to content

Commit

Permalink
[Driver] Make "-fno-split-machine-functions" a valid flag for all archs
Browse files Browse the repository at this point in the history
Previously, clang reports an error when -fno-split-machine-functions
is used for non-X86 archs.

However, in some cases, users may specify flags as
"-fsplit-machine-functions -fother-flags
-fno-split-machine-functions", the first one is from a global flag
set, the last one is used to negate the global flag, we think this is
a valid usage mode.

Another cases is when clang is used to invoke multiple workloads, like
"-x cuda -fsplit-machine-functions -Xarch_device
-fno-split-machine-functions", the latter is used to negate
-fsplit-machine-functions when invoke workloads for GPU."

This change makes this work.

Reviewed By: maskray

Differential Revision: https://reviews.llvm.org/D158755
  • Loading branch information
shenhanc78 committed Aug 24, 2023
1 parent 7195067 commit 7b27167
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 6 additions & 6 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5872,13 +5872,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,

if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
options::OPT_fno_split_machine_functions)) {
// This codegen pass is only available on x86-elf targets.
if (Triple.isX86() && Triple.isOSBinFormatELF()) {
if (A->getOption().matches(options::OPT_fsplit_machine_functions))
if (!A->getOption().matches(options::OPT_fno_split_machine_functions)) {
// This codegen pass is only available on x86-elf targets.
if (Triple.isX86() && Triple.isOSBinFormatELF())
A->render(Args, CmdArgs);
} else {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << TripleStr;
else
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << TripleStr;
}
}

Expand Down
4 changes: 1 addition & 3 deletions clang/test/Driver/fsplit-machine-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@
// RUN: not %clang -### -c --target=arm-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck %s --check-prefix=ERR
// ERR: error: unsupported option '-fsplit-machine-functions' for target

/// FIXME
// RUN: not %clang -### -c --target=arm-unknown-linux -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s --check-prefix=ERR2
// ERR2: error: unsupported option '-fno-split-machine-functions' for target
// RUN: %clang -### --target=arm-unknown-linux -fsplit-machine-functions -fno-split-machine-functions %s

0 comments on commit 7b27167

Please sign in to comment.