aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorLeonard Chan <leonardchan@google.com>2020-08-11 18:03:07 -0700
committerLeonard Chan <leonardchan@google.com>2020-10-14 12:31:21 -0700
commit683b308c07bf827255fe1403056413f790e03729 (patch)
tree15fbfdfa7757f070e9859f4d14451a2d9e7aa44d /clang/lib/Frontend/CompilerInvocation.cpp
parent77638a5343d5b4c1a87ec2b7fb3671ccb108a059 (diff)
downloadllvm-683b308c07bf827255fe1403056413f790e03729.zip
llvm-683b308c07bf827255fe1403056413f790e03729.tar.gz
llvm-683b308c07bf827255fe1403056413f790e03729.tar.bz2
[clang] Add -fc++-abi= flag for specifying which C++ ABI to use
This implements the flag proposed in RFC http://lists.llvm.org/pipermail/cfe-dev/2020-August/066437.html. The goal is to add a way to override the default target C++ ABI through a compiler flag. This makes it easier to test and transition between different C++ ABIs through compile flags rather than build flags. In this patch: - Store `-fc++-abi=` in a LangOpt. This isn't stored in a CodeGenOpt because there are instances outside of codegen where Clang needs to know what the ABI is (particularly through ASTContext::createCXXABI), and we should be able to override the target default if the flag is provided at that point. - Expose the existing ABIs in TargetCXXABI as values that can be passed through this flag. - Create a .def file for these ABIs to make it easier to check flag values. - Add an error for diagnosing bad ABI flag values. Differential Revision: https://reviews.llvm.org/D85802
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index a4c56cc..13320eb 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3513,6 +3513,15 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Args.hasFlag(OPT_fexperimental_relative_cxx_abi_vtables,
OPT_fno_experimental_relative_cxx_abi_vtables,
/*default=*/false);
+
+ // The value can be empty, which indicates the system default should be used.
+ StringRef CXXABI = Args.getLastArgValue(OPT_fcxx_abi_EQ);
+ if (!CXXABI.empty()) {
+ if (!TargetCXXABI::isABI(CXXABI))
+ Diags.Report(diag::err_invalid_cxx_abi) << CXXABI;
+ else
+ Opts.CXXABI = TargetCXXABI::getKind(CXXABI);
+ }
}
static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {