leonardchan created this revision. leonardchan added reviewers: phosek, mcgrathr, rnk. leonardchan added a project: clang. Herald added subscribers: dexonsmith, dang. leonardchan requested review of this revision.
This is a more concentrated version of D85802 <https://reviews.llvm.org/D85802> which added a flag for selecting between any C++ ABI at compile-time. This limits it down to only explicitly using the Fuchsia C++ ABI as per the discussion at the end of that review. This will be used as a way to integrate code built with Clang with code built by other compilers that don't contain Fuchsia-specific ABI changes. The immediate use case is for generating multilibs that use the generic Itanium ABI to be used by code built by GCC. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D93668 Files: clang/include/clang/AST/ASTContext.h clang/include/clang/Basic/LangOptions.h clang/include/clang/Driver/Options.td clang/lib/AST/ASTContext.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp =================================================================== --- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp +++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp @@ -5,6 +5,8 @@ //RUN: | FileCheck --check-prefix=CHECKARM %s //RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s +//RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-linux-gnu -ffuchsia-c++-abi | FileCheck --check-prefix=CHECKFUCHSIA %s +//RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia -fno-fuchsia-c++-abi| FileCheck --check-prefix=CHECKFUCHSIA %s //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32 Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -2831,6 +2831,10 @@ } } + Opts.UseFuchsiaCXXABI = + Args.hasFlag(OPT_ffuchsia_cxx_abi, OPT_fno_fuchsia_cxx_abi, + /*default=*/T.isOSFuchsia()); + std::string ThreadModel = std::string(Args.getLastArgValue(OPT_mthread_model, "posix")); if (ThreadModel != "posix" && ThreadModel != "single") Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -5120,6 +5120,11 @@ /*Default=*/false)) Args.AddLastArg(CmdArgs, options::OPT_ffixed_point); + if (Args.hasFlag(options::OPT_ffuchsia_cxx_abi, + options::OPT_fno_fuchsia_cxx_abi, + /*Default=*/false)) + Args.AddLastArg(CmdArgs, options::OPT_ffuchsia_cxx_abi); + // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} // (-ansi is equivalent to -std=c89 or -std=c++98). // Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -543,7 +543,7 @@ } CodeGen::CGCXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) { - switch (CGM.getTarget().getCXXABI().getKind()) { + switch (CGM.getContext().getCXXABIKind()) { // For IR-generation purposes, there's no significant difference // between the ARM and iOS ABIs. case TargetCXXABI::GenericARM: Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -75,7 +75,7 @@ static const char AnnotationSection[] = "llvm.metadata"; static CGCXXABI *createCXXABI(CodeGenModule &CGM) { - switch (CGM.getTarget().getCXXABI().getKind()) { + switch (CGM.getContext().getCXXABIKind()) { case TargetCXXABI::AppleARM64: case TargetCXXABI::Fuchsia: case TargetCXXABI::GenericAArch64: Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -879,10 +879,18 @@ return CanonTTP; } +TargetCXXABI::Kind ASTContext::getCXXABIKind(const TargetInfo *T) const { + if (getLangOpts().UseFuchsiaCXXABI) + return TargetCXXABI::Fuchsia; + if (T) + return T->getCXXABI().getKind(); + return getTargetInfo().getCXXABI().getKind(); +} + CXXABI *ASTContext::createCXXABI(const TargetInfo &T) { if (!LangOpts.CPlusPlus) return nullptr; - switch (T.getCXXABI().getKind()) { + switch (getCXXABIKind(&T)) { case TargetCXXABI::AppleARM64: case TargetCXXABI::Fuchsia: case TargetCXXABI::GenericARM: // Same as Itanium at this level @@ -10875,7 +10883,7 @@ MangleContext *ASTContext::createMangleContext(const TargetInfo *T) { if (!T) T = Target; - switch (T->getCXXABI().getKind()) { + switch (getCXXABIKind(T)) { case TargetCXXABI::AppleARM64: case TargetCXXABI::Fuchsia: case TargetCXXABI::GenericAArch64: Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1370,6 +1370,11 @@ def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>, Flags<[CC1Option]>, MarshallingInfoString<"CodeGenOpts.SymbolPartition">; +def ffuchsia_cxx_abi : Flag<["-"], "ffuchsia-c++-abi">, Flags<[CC1Option]>, + Group<f_Group>, HelpText<"Explicitly use the Fuchsia C++ ABI">; +def fno_fuchsia_cxx_abi : Flag<["-"], "fno-fuchsia-c++-abi">, Flags<[CC1Option]>, + Group<f_Group>, HelpText<"Do not explicitly use the Fuchsia C++ ABI. Instead use the default C++ ABI indicated by the target">; + defm memory_profile : OptInFFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">; def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">, Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<directory>">, Index: clang/include/clang/Basic/LangOptions.h =================================================================== --- clang/include/clang/Basic/LangOptions.h +++ clang/include/clang/Basic/LangOptions.h @@ -327,6 +327,11 @@ /// input is a header file (i.e. -x c-header). bool IsHeaderFile = false; + /// Indicates that the Fuchsia C++ ABI is being used, either by default + /// through the target triple (ARCH-VENDOR-fuchsia) or explicitly through + /// the -ffuchsia-c++-abi flag. + bool UseFuchsiaCXXABI; + LangOptions(); // Define accessors/mutators for language options of enumeration type. Index: clang/include/clang/AST/ASTContext.h =================================================================== --- clang/include/clang/AST/ASTContext.h +++ clang/include/clang/AST/ASTContext.h @@ -39,6 +39,7 @@ #include "clang/Basic/SanitizerBlacklist.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" +#include "clang/Basic/TargetCXXABI.h" #include "clang/Basic/XRayLists.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/ArrayRef.h" @@ -697,6 +698,11 @@ return FullSourceLoc(Loc,SourceMgr); } + /// Return the C++ ABI kind that should be used. This is located here so the + /// ABI can be overriden by Clang-specific flags at compile-time. If there are + /// no overrides, we instead use the default ABI specified by the target. + TargetCXXABI::Kind getCXXABIKind(const TargetInfo *T = nullptr) const; + /// All comments in this translation unit. RawCommentList Comments;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits