clang 24.0.0git
CIRGenMicrosoftCXXABI.cpp
Go to the documentation of this file.
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
21using namespace clang;
22using namespace clang::CIRGen;
23
24namespace {
25
26class CIRGenMicrosoftCXXABI : public CIRGenCXXABI {
27public:
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 &params) override {
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,
52 bool forVirtualBase,
53 bool delegating) override {
55 "getImplicitConstructorArgs: MSVC ABI");
56 return AddedStructorArgs{};
57 }
58
59 mlir::Value getCXXDestructorImplicitParam(CIRGenFunction &cgf,
60 const CXXDestructorDecl *dd,
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 {
128 "adjustThisArgumentForVirtualFunctionCall: MSVC ABI");
129 return thisAddr;
130 }
131
132 bool isVirtualOffsetNeededForVTableField(CIRGenFunction &cgf,
133 CIRGenFunction::VPtr vptr) override {
134 cgf.cgm.errorNYI("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, "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("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("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("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("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("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(cgf.getLoc(srcTy->getAsCXXRecordDecl()->getLocation()),
275 "emitTypeid: MSVC ABI");
276 return cgf.getBuilder().getNullPtr(
277 typeInfoPtrTy, cgf.getLoc(srcTy->getAsCXXRecordDecl()->getLocation()));
278 }
279
280 void emitBadTypeidCall(CIRGenFunction &cgf, mlir::Location loc) override {
281 cgf.cgm.errorNYI(loc, "emitBadTypeidCall: MSVC ABI");
282 }
283
284 void emitBadCastCall(CIRGenFunction &cgf, mlir::Location loc) override {
285 cgm.errorNYI(loc, "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, "emitDynamicCast: MSVC ABI");
293 return cgf.getBuilder().getNullPtr(destCIRTy, loc);
294 }
295
296 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc,
297 QualType ty) override {
298 cgm.errorNYI(loc, "getAddrOfRTTIDescriptor: MSVC ABI");
299 return nullptr;
300 }
301
302 CatchTypeInfo getCatchAllTypeInfo() override {
303 cgm.errorNYI("getCatchAllTypeInfo: MSVC ABI");
304 return CatchTypeInfo{nullptr, 0};
305 }
306
307 CatchTypeInfo
308 getAddrOfCXXCatchHandlerType(mlir::Location loc, QualType ty,
309 QualType catchHandlerType) override {
310 cgm.errorNYI(loc, "getAddrOfCXXCatchHandlerType: MSVC ABI");
311 return CatchTypeInfo{nullptr, 0};
312 }
313
314 void emitRethrow(CIRGenFunction &cgf, bool isNoReturn) override {
315 cgm.errorNYI("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
331 return new CIRGenMicrosoftCXXABI(cgm);
332}
static RValue performReturnAdjustment(CIRGenFunction &cgf, QualType resultType, RValue rv, const ThunkInfo &thunk)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Definition Address.h:112
Implements C++ ABI-specific code generation functions.
clang::GlobalDecl curGD
The GlobalDecl for the current function being compiled or the global variable currently being initial...
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
CIRGenBuilderTy & getBuilder()
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2293
SourceRange getSourceRange() const
Definition ExprCXX.h:2615
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition DeclCXX.h:624
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Definition CharUnits.h:52
SourceLocation getLocation() const
Definition DeclBase.h:448
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition DeclBase.h:436
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4634
const Decl * getDecl() const
Definition GlobalDecl.h:115
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4990
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9366
QualType getType() const
Definition Decl.h:725
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2171
CIRGenCXXABI * CreateCIRGenMicrosoftCXXABI(CIRGenModule &cgm)
Creates Microsoft ABI.
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
Top level wrappers for InstallAPI frontend operations.
CXXCtorType
C++ constructor types.
Definition ABI.h:24
CXXDtorType
C++ destructor types.
Definition ABI.h:34