This repository was archived by the owner on Feb 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathCIRGenCXXABI.cpp
More file actions
114 lines (96 loc) · 4.16 KB
/
CIRGenCXXABI.cpp
File metadata and controls
114 lines (96 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//===----- CirGenCXXABI.cpp - Interface to C++ ABIs -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This provides an abstract class for C++ code generation. Concrete subclasses
// of this implement code generation for specific C++ ABIs.
//
//===----------------------------------------------------------------------===//
#include "CIRGenCXXABI.h"
#include "clang/AST/Decl.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/AST/Mangle.h"
#include "clang/AST/RecordLayout.h"
using namespace clang;
using namespace clang::CIRGen;
CIRGenCXXABI::~CIRGenCXXABI() {}
CIRGenCXXABI::AddedStructorArgCounts CIRGenCXXABI::addImplicitConstructorArgs(
CIRGenFunction &CGF, const clang::CXXConstructorDecl *D,
clang::CXXCtorType Type, bool ForVirtualBase, bool Delegating,
CallArgList &Args) {
auto AddedArgs =
getImplicitConstructorArgs(CGF, D, Type, ForVirtualBase, Delegating);
for (size_t i = 0; i < AddedArgs.Prefix.size(); ++i)
Args.insert(Args.begin() + 1 + i,
CallArg(RValue::get(AddedArgs.Prefix[i].Value),
AddedArgs.Prefix[i].Type));
for (const auto &arg : AddedArgs.Suffix)
Args.add(RValue::get(arg.Value), arg.Type);
return AddedStructorArgCounts(AddedArgs.Prefix.size(),
AddedArgs.Suffix.size());
}
CatchTypeInfo CIRGenCXXABI::getCatchAllTypeInfo() {
return CatchTypeInfo{nullptr, 0};
}
bool CIRGenCXXABI::NeedsVTTParameter(GlobalDecl GD) { return false; }
void CIRGenCXXABI::buildThisParam(CIRGenFunction &CGF,
FunctionArgList ¶ms) {
const auto *MD = cast<CXXMethodDecl>(CGF.CurGD.getDecl());
// FIXME: I'm not entirely sure I like using a fake decl just for code
// generation. Maybe we can come up with a better way?
auto *ThisDecl =
ImplicitParamDecl::Create(CGM.getASTContext(), nullptr, MD->getLocation(),
&CGM.getASTContext().Idents.get("this"),
MD->getThisType(), ImplicitParamKind::CXXThis);
params.push_back(ThisDecl);
CGF.CXXABIThisDecl = ThisDecl;
// Compute the presumed alignment of 'this', which basically comes down to
// whether we know it's a complete object or not.
auto &Layout = CGF.getContext().getASTRecordLayout(MD->getParent());
if (MD->getParent()->getNumVBases() == 0 ||
MD->getParent()->isEffectivelyFinal() ||
isThisCompleteObject(CGF.CurGD)) {
CGF.CXXABIThisAlignment = Layout.getAlignment();
} else {
CGF.CXXABIThisAlignment = Layout.getNonVirtualAlignment();
}
}
cir::GlobalLinkageKind CIRGenCXXABI::getCXXDestructorLinkage(
GVALinkage Linkage, const CXXDestructorDecl *Dtor, CXXDtorType DT) const {
// Delegate back to CGM by default.
return CGM.getCIRLinkageForDeclarator(Dtor, Linkage,
/*IsConstantVariable=*/false);
}
std::vector<CharUnits> CIRGenCXXABI::getVBPtrOffsets(const CXXRecordDecl *RD) {
return std::vector<CharUnits>();
}
bool CIRGenCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
// Fake answer.
return true;
}
mlir::TypedAttr CIRGenCXXABI::emitNullMemberPointer(clang::QualType T) {
llvm_unreachable("NYI");
}
CharUnits CIRGenCXXABI::getArrayCookieSize(const CXXNewExpr *E) {
if (!requiresArrayCookie(E))
return CharUnits::Zero();
return getArrayCookieSizeImpl(E->getAllocatedType());
}
bool CIRGenCXXABI::requiresArrayCookie(const CXXNewExpr *E) {
// If the class's usual deallocation function takes two arguments,
// it needs a cookie.
if (E->doesUsualArrayDeleteWantSize())
return true;
return E->getAllocatedType().isDestructedType();
}
void CIRGenCXXABI::emitReturnFromThunk(CIRGenFunction &cgf, RValue rv,
QualType resultType) {
assert(!cgf.hasAggregateEvaluationKind(resultType) &&
"cannot handle aggregates");
auto loc = cgf.getBuilder().getUnknownLoc();
cgf.emitReturnOfRValue(loc, rv, resultType);
}