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 mlir::Value getVTableAddressPointInStructor(
152 CIRGenFunction &cgf, const CXXRecordDecl *vtableClass, BaseSubobject base,
153 const CXXRecordDecl *nearestVBase) override {
154 cgf.cgm.errorNYI(vtableClass->getSourceRange(),
155 "getVTableAddressPointInStructor: MSVC ABI");
156 return nullptr;
157 }
158
159 CIRGenCallee getVirtualFunctionPointer(CIRGenFunction &cgf, GlobalDecl gd,
160 Address thisAddr, mlir::Type ty,
161 SourceLocation loc) override {
162 cgf.cgm.errorNYI(loc, "getVirtualFunctionPointer: MSVC ABI");
163 return CIRGenCallee();
164 }
165
166 void emitVTableDefinitions(CIRGenVTables &cgvt,
167 const CXXRecordDecl *rd) override {
168 cgm.errorNYI(rd->getSourceRange(), "emitVTableDefinitions: MSVC ABI");
169 }
170
171 void emitVirtualInheritanceTables(const CXXRecordDecl *rd) override {
172 cgm.errorNYI(rd->getSourceRange(),
173 "emitVirtualInheritanceTables: MSVC ABI");
174 }
175
176 void
177 initializeHiddenVirtualInheritanceMembers(CIRGenFunction &cgf,
178 const CXXRecordDecl *rd) override {
179 cgf.cgm.errorNYI(rd->getSourceRange(),
180 "initializeHiddenVirtualInheritanceMembers: MSVC ABI");
181 }
182
183 mlir::Value
184 getVirtualBaseClassOffset(mlir::Location loc, CIRGenFunction &cgf,
185 Address thisAddr, const CXXRecordDecl *classDecl,
186 const CXXRecordDecl *baseClassDecl) override {
187 cgf.cgm.errorNYI(loc, "getVirtualBaseClassOffset: MSVC ABI");
188 return nullptr;
189 }
190
191 cir::MethodAttr buildVirtualMethodAttr(cir::MethodType methodTy,
192 const CXXMethodDecl *md) override {
193 cgm.errorNYI(md->getSourceRange(), "buildVirtualMethodAttr: MSVC ABI");
194 return cir::MethodAttr();
195 }
196
197 mlir::Value performThisAdjustment(CIRGenFunction &cgf, Address thisAddr,
198 const CXXRecordDecl *unadjustedClass,
199 const ThunkInfo &ti) override {
200 cgf.cgm.errorNYI("performThisAdjustment: MSVC ABI");
201 return thisAddr.emitRawPointer();
202 }
203
204 mlir::Value performReturnAdjustment(CIRGenFunction &cgf, Address ret,
205 const CXXRecordDecl *unadjustedClass,
206 const ReturnAdjustment &ra) override {
207 cgf.cgm.errorNYI("performReturnAdjustment: MSVC ABI");
208 return ret.emitRawPointer();
209 }
210
211 bool canSpeculativelyEmitVTable(const CXXRecordDecl *rd) const override {
212 return false;
213 }
214
215 bool doStructorsInitializeVPtrs(const CXXRecordDecl *vtableClass) override {
216 cgm.errorNYI(vtableClass->getSourceRange(),
217 "doStructorsInitializeVPtrs: MSVC ABI");
218 return false;
219 }
220
221 bool exportThunk() override { return false; }
222
223 bool useThunkForDtorVariant(const CXXDestructorDecl *dtor,
224 CXXDtorType dt) const override {
225 cgm.errorNYI(dtor->getSourceRange(), "useThunkForDtorVariant: MSVC ABI");
226 return false;
227 }
228
229 void setThunkLinkage(cir::FuncOp thunk, bool forVTable, GlobalDecl gd,
230 bool returnAdjustment) override {
231 cgm.errorNYI(gd.getDecl()->getSourceRange(), "setThunkLinkage: MSVC ABI");
232 }
233
234 StringRef getPureVirtualCallName() override { return "_purecall"; }
235 StringRef getDeletedVirtualCallName() override { return "_purecall"; }
236
237 bool isZeroInitializable(const MemberPointerType *mpt) override {
238 cgm.errorNYI("isZeroInitializable: MSVC ABI");
239 return true;
240 }
241
242 bool requiresArrayCookie(const CXXNewExpr *e) override {
243 cgm.errorNYI(e->getSourceRange(), "requiresArrayCookie: MSVC ABI");
244 return false;
245 }
246
247 CharUnits getArrayCookieSizeImpl(QualType elementType) override {
248 cgm.errorNYI("getArrayCookieSizeImpl: MSVC ABI");
249 return CharUnits::Zero();
250 }
251
252 Address initializeArrayCookie(CIRGenFunction &cgf, Address newPtr,
253 mlir::Value numElements, const CXXNewExpr *e,
254 QualType elementType) override {
255 cgf.cgm.errorNYI(e->getSourceRange(), "initializeArrayCookie: MSVC ABI");
256 return newPtr;
257 }
258
259 bool shouldTypeidBeNullChecked(QualType srcTy) override {
260 cgm.errorNYI("shouldTypeidBeNullChecked: MSVC ABI");
261 return false;
262 }
263
264 mlir::Value emitTypeid(CIRGenFunction &cgf, QualType srcTy, Address thisPtr,
265 mlir::Type typeInfoPtrTy) override {
266 cgf.cgm.errorNYI(cgf.getLoc(srcTy->getAsCXXRecordDecl()->getLocation()),
267 "emitTypeid: MSVC ABI");
268 return cgf.getBuilder().getNullPtr(
269 typeInfoPtrTy, cgf.getLoc(srcTy->getAsCXXRecordDecl()->getLocation()));
270 }
271
272 void emitBadTypeidCall(CIRGenFunction &cgf, mlir::Location loc) override {
273 cgf.cgm.errorNYI(loc, "emitBadTypeidCall: MSVC ABI");
274 }
275
276 void emitBadCastCall(CIRGenFunction &cgf, mlir::Location loc) override {
277 cgm.errorNYI(loc, "emitBadCastCall: MSVC ABI");
278 }
279
280 mlir::Value emitDynamicCast(CIRGenFunction &cgf, mlir::Location loc,
281 QualType srcRecordTy, QualType destRecordTy,
282 cir::PointerType destCIRTy, bool isRefCast,
283 Address src) override {
284 cgf.cgm.errorNYI(loc, "emitDynamicCast: MSVC ABI");
285 return cgf.getBuilder().getNullPtr(destCIRTy, loc);
286 }
287
288 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc,
289 QualType ty) override {
290 cgm.errorNYI(loc, "getAddrOfRTTIDescriptor: MSVC ABI");
291 return nullptr;
292 }
293
294 CatchTypeInfo getCatchAllTypeInfo() override {
295 cgm.errorNYI("getCatchAllTypeInfo: MSVC ABI");
296 return CatchTypeInfo{nullptr, 0};
297 }
298
299 CatchTypeInfo
300 getAddrOfCXXCatchHandlerType(mlir::Location loc, QualType ty,
301 QualType catchHandlerType) override {
302 cgm.errorNYI(loc, "getAddrOfCXXCatchHandlerType: MSVC ABI");
303 return CatchTypeInfo{nullptr, 0};
304 }
305
306 void emitRethrow(CIRGenFunction &cgf, bool isNoReturn) override {
307 cgm.errorNYI("emitRethrow: MSVC ABI");
308 }
309
310 void emitThrow(CIRGenFunction &cgf, const CXXThrowExpr *e) override {
311 cgf.cgm.errorNYI(e->getSourceRange(), "emitThrow: MSVC ABI");
312 }
313
314 void registerGlobalDtor(const VarDecl *vd, cir::FuncOp dtor,
315 mlir::Value addr) override {
316 cgm.errorNYI(vd->getSourceRange(), "registerGlobalDtor: MSVC ABI");
317 }
318};
319
320} // namespace
321
323 return new CIRGenMicrosoftCXXABI(cgm);
324}
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:2292
SourceRange getSourceRange() const
Definition ExprCXX.h:2614
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition DeclCXX.h:623
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition CharUnits.h:53
SourceLocation getLocation() const
Definition DeclBase.h:447
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition DeclBase.h:435
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4608
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:4958
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:9331
QualType getType() const
Definition Decl.h:724
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2170
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