diff --git a/clang/include/clang/Basic/TargetCXXABI.h b/clang/include/clang/Basic/TargetCXXABI.h --- a/clang/include/clang/Basic/TargetCXXABI.h +++ b/clang/include/clang/Basic/TargetCXXABI.h @@ -109,6 +109,13 @@ /// - constructors and destructors return 'this', as in ARM. Fuchsia, + /// The XL ABI is the ABI used by IBM xlclang compiler and 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 +155,7 @@ case WatchOS: case GenericMIPS: case WebAssembly: + case XL: return true; case Microsoft: @@ -168,6 +176,7 @@ case WatchOS: case GenericMIPS: case WebAssembly: + case XL: return false; case Microsoft: @@ -202,6 +211,7 @@ case iOS64: case WatchOS: case Microsoft: + case XL: return true; } llvm_unreachable("bad ABI kind"); @@ -278,6 +288,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 +326,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 diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/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); @@ -10253,6 +10254,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()); diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/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 { diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/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); diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/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."); +} diff --git a/clang/test/CodeGen/static-init.cpp b/clang/test/CodeGen/static-init.cpp new file mode 100644 --- /dev/null +++ b/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.