From 683b308c07bf827255fe1403056413f790e03729 Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Tue, 11 Aug 2020 18:03:07 -0700 Subject: [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 --- clang/lib/CodeGen/CodeGenModule.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 93b49ec981e8..aaf20ea5e41c 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -75,19 +75,14 @@ static llvm::cl::opt LimitedCoverage( static const char AnnotationSection[] = "llvm.metadata"; static CGCXXABI *createCXXABI(CodeGenModule &CGM) { - switch (CGM.getTarget().getCXXABI().getKind()) { - case TargetCXXABI::Fuchsia: - case TargetCXXABI::GenericAArch64: - case TargetCXXABI::GenericARM: - case TargetCXXABI::iOS: - case TargetCXXABI::iOS64: - case TargetCXXABI::WatchOS: - case TargetCXXABI::GenericMIPS: - case TargetCXXABI::GenericItanium: - case TargetCXXABI::WebAssembly: - case TargetCXXABI::XL: + switch (CGM.getContext().getCXXABIKind()) { +#define ITANIUM_CXXABI(Name, Str) case TargetCXXABI::Name: +#define CXXABI(Name, Str) +#include "clang/Basic/TargetCXXABI.def" return CreateItaniumCXXABI(CGM); - case TargetCXXABI::Microsoft: +#define MICROSOFT_CXXABI(Name, Str) case TargetCXXABI::Name: +#define CXXABI(Name, Str) +#include "clang/Basic/TargetCXXABI.def" return CreateMicrosoftCXXABI(CGM); } -- cgit v1.2.3