| 1 | //===--- CIRGenMicrosoftCXXABI.cpp - Emit CIR Code for MS C++ ABI --------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This provides C++ code generation targeting the Microsoft C++ ABI. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "CIRGenCXXABI.h" |
| 14 | #include "CIRGenFunction.h" |
| 15 | #include "CIRGenModule.h" |
| 16 | |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclCXX.h" |
| 19 | #include "clang/AST/Mangle.h" |
| 20 | |
| 21 | using namespace clang; |
| 22 | using namespace clang::CIRGen; |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | class CIRGenMicrosoftCXXABI : public CIRGenCXXABI { |
| 27 | public: |
| 28 | CIRGenMicrosoftCXXABI(CIRGenModule &cgm) : CIRGenCXXABI(cgm) {} |
| 29 | |
| 30 | AddedStructorArgCounts |
| 31 | buildStructorSignature(GlobalDecl gd, |
| 32 | SmallVectorImpl<CanQualType> &argTys) override { |
| 33 | cgm.errorNYI(gd.getDecl()->getSourceRange(), |
| 34 | "buildStructorSignature: MSVC ABI" ); |
| 35 | return AddedStructorArgCounts{}; |
| 36 | } |
| 37 | |
| 38 | void addImplicitStructorParams(CIRGenFunction &cgf, QualType &resTy, |
| 39 | FunctionArgList ¶ms) override { |
| 40 | cgf.cgm.errorNYI(cgf.curGD.getDecl()->getSourceRange(), |
| 41 | "addImplicitStructorParams: MSVC ABI" ); |
| 42 | } |
| 43 | |
| 44 | void emitInstanceFunctionProlog(SourceLocation loc, |
| 45 | CIRGenFunction &cgf) override { |
| 46 | cgf.cgm.errorNYI(loc, "emitInstanceFunctionProlog: MSVC ABI" ); |
| 47 | } |
| 48 | |
| 49 | AddedStructorArgs getImplicitConstructorArgs(CIRGenFunction &cgf, |
| 50 | const CXXConstructorDecl *d, |
| 51 | CXXCtorType type, |
| 52 | bool forVirtualBase, |
| 53 | bool delegating) override { |
| 54 | cgf.cgm.errorNYI(d->getSourceRange(), |
| 55 | "getImplicitConstructorArgs: MSVC ABI" ); |
| 56 | return AddedStructorArgs{}; |
| 57 | } |
| 58 | |
| 59 | mlir::Value getCXXDestructorImplicitParam(CIRGenFunction &cgf, |
| 60 | const CXXDestructorDecl *dd, |
| 61 | CXXDtorType type, |
| 62 | bool forVirtualBase, |
| 63 | bool delegating) override { |
| 64 | cgf.cgm.errorNYI(dd->getSourceRange(), |
| 65 | "getCXXDestructorImplicitParam: MSVC ABI" ); |
| 66 | return nullptr; |
| 67 | } |
| 68 | |
| 69 | void emitCXXConstructors(const CXXConstructorDecl *d) override { |
| 70 | cgm.errorNYI(d->getSourceRange(), "emitCXXConstructors: MSVC ABI" ); |
| 71 | } |
| 72 | |
| 73 | void emitCXXDestructors(const CXXDestructorDecl *d) override { |
| 74 | cgm.errorNYI(d->getSourceRange(), "emitCXXDestructors: MSVC ABI" ); |
| 75 | } |
| 76 | |
| 77 | void emitCXXStructor(GlobalDecl gd) override { |
| 78 | cgm.errorNYI(gd.getDecl()->getSourceRange(), "emitCXXStructor: MSVC ABI" ); |
| 79 | } |
| 80 | |
| 81 | void emitDestructorCall(CIRGenFunction &cgf, const CXXDestructorDecl *dd, |
| 82 | CXXDtorType type, bool forVirtualBase, |
| 83 | bool delegating, Address thisAddr, |
| 84 | QualType thisTy) override { |
| 85 | cgf.cgm.errorNYI(dd->getSourceRange(), "emitDestructorCall: MSVC ABI" ); |
| 86 | } |
| 87 | |
| 88 | mlir::Value emitVirtualDestructorCall(CIRGenFunction &cgf, |
| 89 | const CXXDestructorDecl *dtor, |
| 90 | CXXDtorType dtorType, Address thisAddr, |
| 91 | DeleteOrMemberCallExpr e) override { |
| 92 | cgf.cgm.errorNYI(dtor->getSourceRange(), |
| 93 | "emitVirtualDestructorCall: MSVC ABI" ); |
| 94 | return nullptr; |
| 95 | } |
| 96 | |
| 97 | void emitVirtualObjectDelete(CIRGenFunction &cgf, const CXXDeleteExpr *de, |
| 98 | Address ptr, QualType elementType, |
| 99 | const CXXDestructorDecl *dtor) override { |
| 100 | cgf.cgm.errorNYI(de->getSourceRange(), "emitVirtualObjectDelete: MSVC ABI" ); |
| 101 | } |
| 102 | |
| 103 | size_t getSrcArgforCopyCtor(const CXXConstructorDecl *cd, |
| 104 | FunctionArgList &args) const override { |
| 105 | cgm.errorNYI(cd->getSourceRange(), "getSrcArgforCopyCtor: MSVC ABI" ); |
| 106 | assert(args.size() >= 2 && |
| 107 | "expected the arglist to have at least two args!" ); |
| 108 | // The 'most_derived' parameter goes second if the ctor is variadic and |
| 109 | // has v-bases. |
| 110 | if (cd->getParent()->getNumVBases() > 0 && |
| 111 | cd->getType()->castAs<FunctionProtoType>()->isVariadic()) |
| 112 | return 2; |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | const CXXRecordDecl * |
| 117 | getThisArgumentTypeForMethod(const CXXMethodDecl *md) override { |
| 118 | cgm.errorNYI(md->getSourceRange(), |
| 119 | "getThisArgumentTypeForMethod: MSVC ABI" ); |
| 120 | return md->getParent(); |
| 121 | } |
| 122 | |
| 123 | Address adjustThisArgumentForVirtualFunctionCall(CIRGenFunction &cgf, |
| 124 | GlobalDecl gd, |
| 125 | Address thisAddr, |
| 126 | bool virtualCall) override { |
| 127 | cgf.cgm.errorNYI(gd.getDecl()->getSourceRange(), |
| 128 | "adjustThisArgumentForVirtualFunctionCall: MSVC ABI" ); |
| 129 | return thisAddr; |
| 130 | } |
| 131 | |
| 132 | bool isVirtualOffsetNeededForVTableField(CIRGenFunction &cgf, |
| 133 | CIRGenFunction::VPtr vptr) override { |
| 134 | cgf.cgm.errorNYI(feature: "isVirtualOffsetNeededForVTableField: MSVC ABI" ); |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | cir::GlobalOp getAddrOfVTable(const CXXRecordDecl *rd, |
| 139 | CharUnits vptrOffset) override { |
| 140 | cgm.errorNYI(rd->getSourceRange(), "getAddrOfVTable: MSVC ABI" ); |
| 141 | return nullptr; |
| 142 | } |
| 143 | |
| 144 | mlir::Value getVTableAddressPoint(BaseSubobject base, |
| 145 | const CXXRecordDecl *vtableClass) override { |
| 146 | cgm.errorNYI(vtableClass->getSourceRange(), |
| 147 | "getVTableAddressPoint: MSVC ABI" ); |
| 148 | return nullptr; |
| 149 | } |
| 150 | |
| 151 | cir::GlobalViewAttr |
| 152 | getVTableAddressPointAttr(BaseSubobject base, |
| 153 | const CXXRecordDecl *vtableClass) override { |
| 154 | cgm.errorNYI(vtableClass->getSourceRange(), |
| 155 | "getVTableAddressPointAttr: MSVC ABI" ); |
| 156 | return {}; |
| 157 | } |
| 158 | |
| 159 | mlir::Value getVTableAddressPointInStructor( |
| 160 | CIRGenFunction &cgf, const CXXRecordDecl *vtableClass, BaseSubobject base, |
| 161 | const CXXRecordDecl *nearestVBase) override { |
| 162 | cgf.cgm.errorNYI(vtableClass->getSourceRange(), |
| 163 | "getVTableAddressPointInStructor: MSVC ABI" ); |
| 164 | return nullptr; |
| 165 | } |
| 166 | |
| 167 | CIRGenCallee getVirtualFunctionPointer(CIRGenFunction &cgf, GlobalDecl gd, |
| 168 | Address thisAddr, mlir::Type ty, |
| 169 | SourceLocation loc) override { |
| 170 | cgf.cgm.errorNYI(loc, "getVirtualFunctionPointer: MSVC ABI" ); |
| 171 | return CIRGenCallee(); |
| 172 | } |
| 173 | |
| 174 | void emitVTableDefinitions(CIRGenVTables &cgvt, |
| 175 | const CXXRecordDecl *rd) override { |
| 176 | cgm.errorNYI(rd->getSourceRange(), "emitVTableDefinitions: MSVC ABI" ); |
| 177 | } |
| 178 | |
| 179 | void emitVirtualInheritanceTables(const CXXRecordDecl *rd) override { |
| 180 | cgm.errorNYI(rd->getSourceRange(), |
| 181 | "emitVirtualInheritanceTables: MSVC ABI" ); |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | initializeHiddenVirtualInheritanceMembers(CIRGenFunction &cgf, |
| 186 | const CXXRecordDecl *rd) override { |
| 187 | cgf.cgm.errorNYI(rd->getSourceRange(), |
| 188 | "initializeHiddenVirtualInheritanceMembers: MSVC ABI" ); |
| 189 | } |
| 190 | |
| 191 | mlir::Value |
| 192 | getVirtualBaseClassOffset(mlir::Location loc, CIRGenFunction &cgf, |
| 193 | Address thisAddr, const CXXRecordDecl *classDecl, |
| 194 | const CXXRecordDecl *baseClassDecl) override { |
| 195 | cgf.cgm.errorNYI(loc, feature: "getVirtualBaseClassOffset: MSVC ABI" ); |
| 196 | return nullptr; |
| 197 | } |
| 198 | |
| 199 | cir::MethodAttr buildVirtualMethodAttr(cir::MethodType methodTy, |
| 200 | const CXXMethodDecl *md) override { |
| 201 | cgm.errorNYI(md->getSourceRange(), "buildVirtualMethodAttr: MSVC ABI" ); |
| 202 | return cir::MethodAttr(); |
| 203 | } |
| 204 | |
| 205 | mlir::Value performThisAdjustment(CIRGenFunction &cgf, Address thisAddr, |
| 206 | const CXXRecordDecl *unadjustedClass, |
| 207 | const ThunkInfo &ti) override { |
| 208 | cgf.cgm.errorNYI(feature: "performThisAdjustment: MSVC ABI" ); |
| 209 | return thisAddr.emitRawPointer(); |
| 210 | } |
| 211 | |
| 212 | mlir::Value performReturnAdjustment(CIRGenFunction &cgf, Address ret, |
| 213 | const CXXRecordDecl *unadjustedClass, |
| 214 | const ReturnAdjustment &ra) override { |
| 215 | cgf.cgm.errorNYI(feature: "performReturnAdjustment: MSVC ABI" ); |
| 216 | return ret.emitRawPointer(); |
| 217 | } |
| 218 | |
| 219 | bool canSpeculativelyEmitVTable(const CXXRecordDecl *rd) const override { |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | bool doStructorsInitializeVPtrs(const CXXRecordDecl *vtableClass) override { |
| 224 | cgm.errorNYI(vtableClass->getSourceRange(), |
| 225 | "doStructorsInitializeVPtrs: MSVC ABI" ); |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | bool exportThunk() override { return false; } |
| 230 | |
| 231 | bool useThunkForDtorVariant(const CXXDestructorDecl *dtor, |
| 232 | CXXDtorType dt) const override { |
| 233 | cgm.errorNYI(dtor->getSourceRange(), "useThunkForDtorVariant: MSVC ABI" ); |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | void setThunkLinkage(cir::FuncOp thunk, bool forVTable, GlobalDecl gd, |
| 238 | bool returnAdjustment) override { |
| 239 | cgm.errorNYI(gd.getDecl()->getSourceRange(), "setThunkLinkage: MSVC ABI" ); |
| 240 | } |
| 241 | |
| 242 | StringRef getPureVirtualCallName() override { return "_purecall" ; } |
| 243 | StringRef getDeletedVirtualCallName() override { return "_purecall" ; } |
| 244 | |
| 245 | bool isZeroInitializable(const MemberPointerType *mpt) override { |
| 246 | cgm.errorNYI(feature: "isZeroInitializable: MSVC ABI" ); |
| 247 | return true; |
| 248 | } |
| 249 | |
| 250 | bool requiresArrayCookie(const CXXNewExpr *e) override { |
| 251 | cgm.errorNYI(e->getSourceRange(), "requiresArrayCookie: MSVC ABI" ); |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | CharUnits getArrayCookieSizeImpl(QualType elementType) override { |
| 256 | cgm.errorNYI(feature: "getArrayCookieSizeImpl: MSVC ABI" ); |
| 257 | return CharUnits::Zero(); |
| 258 | } |
| 259 | |
| 260 | Address initializeArrayCookie(CIRGenFunction &cgf, Address newPtr, |
| 261 | mlir::Value numElements, const CXXNewExpr *e, |
| 262 | QualType elementType) override { |
| 263 | cgf.cgm.errorNYI(e->getSourceRange(), "initializeArrayCookie: MSVC ABI" ); |
| 264 | return newPtr; |
| 265 | } |
| 266 | |
| 267 | bool shouldTypeidBeNullChecked(QualType srcTy) override { |
| 268 | cgm.errorNYI(feature: "shouldTypeidBeNullChecked: MSVC ABI" ); |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | mlir::Value emitTypeid(CIRGenFunction &cgf, QualType srcTy, Address thisPtr, |
| 273 | mlir::Type typeInfoPtrTy) override { |
| 274 | cgf.cgm.errorNYI(loc: cgf.getLoc(srcLoc: srcTy->getAsCXXRecordDecl()->getLocation()), |
| 275 | feature: "emitTypeid: MSVC ABI" ); |
| 276 | return cgf.getBuilder().getNullPtr( |
| 277 | ty: typeInfoPtrTy, loc: cgf.getLoc(srcLoc: srcTy->getAsCXXRecordDecl()->getLocation())); |
| 278 | } |
| 279 | |
| 280 | void emitBadTypeidCall(CIRGenFunction &cgf, mlir::Location loc) override { |
| 281 | cgf.cgm.errorNYI(loc, feature: "emitBadTypeidCall: MSVC ABI" ); |
| 282 | } |
| 283 | |
| 284 | void emitBadCastCall(CIRGenFunction &cgf, mlir::Location loc) override { |
| 285 | cgm.errorNYI(loc, feature: "emitBadCastCall: MSVC ABI" ); |
| 286 | } |
| 287 | |
| 288 | mlir::Value emitDynamicCast(CIRGenFunction &cgf, mlir::Location loc, |
| 289 | QualType srcRecordTy, QualType destRecordTy, |
| 290 | cir::PointerType destCIRTy, bool isRefCast, |
| 291 | Address src) override { |
| 292 | cgf.cgm.errorNYI(loc, feature: "emitDynamicCast: MSVC ABI" ); |
| 293 | return cgf.getBuilder().getNullPtr(ty: destCIRTy, loc); |
| 294 | } |
| 295 | |
| 296 | mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, |
| 297 | QualType ty) override { |
| 298 | cgm.errorNYI(loc, feature: "getAddrOfRTTIDescriptor: MSVC ABI" ); |
| 299 | return nullptr; |
| 300 | } |
| 301 | |
| 302 | CatchTypeInfo getCatchAllTypeInfo() override { |
| 303 | cgm.errorNYI(feature: "getCatchAllTypeInfo: MSVC ABI" ); |
| 304 | return CatchTypeInfo{.rtti: nullptr, .flags: 0}; |
| 305 | } |
| 306 | |
| 307 | CatchTypeInfo |
| 308 | getAddrOfCXXCatchHandlerType(mlir::Location loc, QualType ty, |
| 309 | QualType catchHandlerType) override { |
| 310 | cgm.errorNYI(loc, feature: "getAddrOfCXXCatchHandlerType: MSVC ABI" ); |
| 311 | return CatchTypeInfo{.rtti: nullptr, .flags: 0}; |
| 312 | } |
| 313 | |
| 314 | void emitRethrow(CIRGenFunction &cgf, bool isNoReturn) override { |
| 315 | cgm.errorNYI(feature: "emitRethrow: MSVC ABI" ); |
| 316 | } |
| 317 | |
| 318 | void emitThrow(CIRGenFunction &cgf, const CXXThrowExpr *e) override { |
| 319 | cgf.cgm.errorNYI(e->getSourceRange(), "emitThrow: MSVC ABI" ); |
| 320 | } |
| 321 | |
| 322 | void registerGlobalDtor(const VarDecl *vd, cir::FuncOp dtor, |
| 323 | mlir::Value addr) override { |
| 324 | cgm.errorNYI(vd->getSourceRange(), "registerGlobalDtor: MSVC ABI" ); |
| 325 | } |
| 326 | }; |
| 327 | |
| 328 | } // namespace |
| 329 | |
| 330 | CIRGenCXXABI *clang::CIRGen::CreateCIRGenMicrosoftCXXABI(CIRGenModule &cgm) { |
| 331 | return new CIRGenMicrosoftCXXABI(cgm); |
| 332 | } |
| 333 | |