Index: clang/include/clang/Basic/TargetCXXABI.h =================================================================== --- clang/include/clang/Basic/TargetCXXABI.h +++ clang/include/clang/Basic/TargetCXXABI.h @@ -109,6 +109,12 @@ /// - constructors and destructors return 'this', as in ARM. Fuchsia, + /// The XL ABI is a modified version of the Itanium ABI. + /// + /// The relevant changes from the Itanium ABI are: + /// - static initialization is adjusted to use sinit and sterm functions; + XL, + /// The Microsoft ABI is the ABI used by Microsoft Visual Studio (and /// compatible compilers). /// @@ -148,6 +154,7 @@ case WatchOS: case GenericMIPS: case WebAssembly: + case XL: return true; case Microsoft: @@ -168,6 +175,7 @@ case WatchOS: case GenericMIPS: case WebAssembly: + case XL: return false; case Microsoft: @@ -202,6 +210,7 @@ case iOS64: case WatchOS: case Microsoft: + case XL: return true; } llvm_unreachable("bad ABI kind"); @@ -278,6 +287,7 @@ case iOS: // old iOS compilers did not follow this rule case Microsoft: case GenericMIPS: + case XL: return true; } llvm_unreachable("bad ABI kind"); @@ -315,6 +325,7 @@ case GenericARM: case iOS: case GenericMIPS: + case XL: return UseTailPaddingUnlessPOD03; // iOS on ARM64 and WebAssembly use the C++11 POD rules. They do not honor Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -874,6 +874,7 @@ case TargetCXXABI::GenericMIPS: case TargetCXXABI::GenericItanium: case TargetCXXABI::WebAssembly: + case TargetCXXABI::XL: return CreateItaniumCXXABI(*this); case TargetCXXABI::Microsoft: return CreateMicrosoftCXXABI(*this); @@ -10251,6 +10252,7 @@ case TargetCXXABI::iOS64: case TargetCXXABI::WebAssembly: case TargetCXXABI::WatchOS: + case TargetCXXABI::XL: return ItaniumMangleContext::create(*this, getDiagnostics()); case TargetCXXABI::Microsoft: return MicrosoftMangleContext::create(*this, getDiagnostics()); Index: clang/lib/Basic/Targets/OSTargets.h =================================================================== --- clang/lib/Basic/Targets/OSTargets.h +++ clang/lib/Basic/Targets/OSTargets.h @@ -706,6 +706,8 @@ public: AIXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : OSTargetInfo(Triple, Opts) { + this->TheCXXABI.set(TargetCXXABI::XL); + if (this->PointerWidth == 64) { this->WCharType = this->UnsignedInt; } else { Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -83,6 +83,7 @@ case TargetCXXABI::GenericMIPS: case TargetCXXABI::GenericItanium: case TargetCXXABI::WebAssembly: + case TargetCXXABI::XL: return CreateItaniumCXXABI(CGM); case TargetCXXABI::Microsoft: return CreateMicrosoftCXXABI(CGM); Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -516,6 +516,16 @@ } bool canCallMismatchedFunctionType() const override { return false; } }; + +class XLCXXABI final : public ItaniumCXXABI { +public: + explicit XLCXXABI(CodeGen::CodeGenModule &CGM) + : ItaniumCXXABI(CGM) {} + + void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, + llvm::FunctionCallee dtor, + llvm::Constant *addr) override; +}; } CodeGen::CGCXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) { @@ -546,6 +556,9 @@ case TargetCXXABI::WebAssembly: return new WebAssemblyCXXABI(CGM); + case TargetCXXABI::XL: + return new XLCXXABI(CGM); + case TargetCXXABI::GenericItanium: if (CGM.getContext().getTargetInfo().getTriple().getArch() == llvm::Triple::le32) { @@ -4407,3 +4420,11 @@ NormalCleanup, cast(CGF.CurrentFuncletPad)); ItaniumCXXABI::emitBeginCatch(CGF, C); } + +/// Register a global destructor as best as we know how. +void XLCXXABI::registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, + llvm::FunctionCallee dtor, + llvm::Constant *addr) { + llvm::report_fatal_error("Static initialization has not been implemented on" + " XL ABI yet."); +} Index: clang/test/CodeGen/static-init.cpp =================================================================== --- /dev/null +++ clang/test/CodeGen/static-init.cpp @@ -0,0 +1,12 @@ +// RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ %s \ +// RUN: 2>&1 | FileCheck %s + +// RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ %s \ +// RUN: 2>&1 | FileCheck %s + +struct test { + test(); + ~test(); +} t; + +// CHECK: error in backend: Static initialization has not been implemented on XL ABI yet.