2018-02-28 15:15:55 +08:00
|
|
|
//===--- CGNonTrivialStruct.cpp - Emit Special Functions for C Structs ----===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2018-02-28 15:15:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines functions to generate various special functions for C
|
|
|
|
// structs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "CodeGenModule.h"
|
2018-04-18 03:05:17 +08:00
|
|
|
#include "clang/AST/NonTrivialTypeVisitor.h"
|
2019-04-11 03:57:20 +08:00
|
|
|
#include "clang/CodeGen/CodeGenABITypes.h"
|
2018-02-28 15:15:55 +08:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
|
|
|
// Return the size of a field in number of bits.
|
2018-04-17 04:23:52 +08:00
|
|
|
static uint64_t getFieldSize(const FieldDecl *FD, QualType FT,
|
|
|
|
ASTContext &Ctx) {
|
|
|
|
if (FD && FD->isBitField())
|
2018-02-28 15:15:55 +08:00
|
|
|
return FD->getBitWidthValue(Ctx);
|
2018-04-17 04:23:52 +08:00
|
|
|
return Ctx.getTypeSize(FT);
|
2018-02-28 15:15:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
enum { DstIdx = 0, SrcIdx = 1 };
|
|
|
|
const char *ValNameStr[2] = {"dst", "src"};
|
|
|
|
|
|
|
|
template <class Derived> struct StructVisitor {
|
|
|
|
StructVisitor(ASTContext &Ctx) : Ctx(Ctx) {}
|
|
|
|
|
|
|
|
template <class... Ts>
|
|
|
|
void visitStructFields(QualType QT, CharUnits CurStructOffset, Ts... Args) {
|
|
|
|
const RecordDecl *RD = QT->castAs<RecordType>()->getDecl();
|
|
|
|
|
|
|
|
// Iterate over the fields of the struct.
|
|
|
|
for (const FieldDecl *FD : RD->fields()) {
|
|
|
|
QualType FT = FD->getType();
|
|
|
|
FT = QT.isVolatileQualified() ? FT.withVolatile() : FT;
|
|
|
|
asDerived().visit(FT, FD, CurStructOffset, Args...);
|
|
|
|
}
|
|
|
|
|
|
|
|
asDerived().flushTrivialFields(Args...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ts> void visitTrivial(Ts... Args) {}
|
|
|
|
|
|
|
|
template <class... Ts> void visitCXXDestructor(Ts... Args) {
|
|
|
|
llvm_unreachable("field of a C++ struct type is not expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ts> void flushTrivialFields(Ts... Args) {}
|
|
|
|
|
|
|
|
uint64_t getFieldOffsetInBits(const FieldDecl *FD) {
|
|
|
|
return FD ? Ctx.getASTRecordLayout(FD->getParent())
|
|
|
|
.getFieldOffset(FD->getFieldIndex())
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CharUnits getFieldOffset(const FieldDecl *FD) {
|
|
|
|
return Ctx.toCharUnitsFromBits(getFieldOffsetInBits(FD));
|
|
|
|
}
|
|
|
|
|
|
|
|
Derived &asDerived() { return static_cast<Derived &>(*this); }
|
|
|
|
|
|
|
|
ASTContext &getContext() { return Ctx; }
|
|
|
|
ASTContext &Ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Derived, bool IsMove>
|
|
|
|
struct CopyStructVisitor : StructVisitor<Derived>,
|
|
|
|
CopiedTypeVisitor<Derived, IsMove> {
|
|
|
|
using StructVisitor<Derived>::asDerived;
|
2018-04-18 03:05:17 +08:00
|
|
|
using Super = CopiedTypeVisitor<Derived, IsMove>;
|
2018-02-28 15:15:55 +08:00
|
|
|
|
|
|
|
CopyStructVisitor(ASTContext &Ctx) : StructVisitor<Derived>(Ctx) {}
|
|
|
|
|
|
|
|
template <class... Ts>
|
|
|
|
void preVisit(QualType::PrimitiveCopyKind PCK, QualType FT,
|
2019-03-29 08:23:17 +08:00
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset, Ts &&... Args) {
|
2018-02-28 15:15:55 +08:00
|
|
|
if (PCK)
|
|
|
|
asDerived().flushTrivialFields(std::forward<Ts>(Args)...);
|
|
|
|
}
|
|
|
|
|
2018-04-18 03:05:17 +08:00
|
|
|
template <class... Ts>
|
|
|
|
void visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT,
|
2019-03-29 08:23:17 +08:00
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-04-18 03:05:17 +08:00
|
|
|
Ts &&... Args) {
|
|
|
|
if (const auto *AT = asDerived().getContext().getAsArrayType(FT)) {
|
|
|
|
asDerived().visitArray(PCK, AT, FT.isVolatileQualified(), FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CurStructOffset, std::forward<Ts>(Args)...);
|
2018-04-18 03:05:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
Super::visitWithKind(PCK, FT, FD, CurStructOffset,
|
2018-04-18 03:05:17 +08:00
|
|
|
std::forward<Ts>(Args)...);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
template <class... Ts>
|
|
|
|
void visitTrivial(QualType FT, const FieldDecl *FD, CharUnits CurStructOffset,
|
|
|
|
Ts... Args) {
|
|
|
|
assert(!FT.isVolatileQualified() && "volatile field not expected");
|
|
|
|
ASTContext &Ctx = asDerived().getContext();
|
2018-04-17 04:23:52 +08:00
|
|
|
uint64_t FieldSize = getFieldSize(FD, FT, Ctx);
|
2018-02-28 15:15:55 +08:00
|
|
|
|
|
|
|
// Ignore zero-sized fields.
|
|
|
|
if (FieldSize == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint64_t FStartInBits = asDerived().getFieldOffsetInBits(FD);
|
|
|
|
uint64_t FEndInBits = FStartInBits + FieldSize;
|
|
|
|
uint64_t RoundedFEnd = llvm::alignTo(FEndInBits, Ctx.getCharWidth());
|
|
|
|
|
|
|
|
// Set Start if this is the first field of a sequence of trivial fields.
|
|
|
|
if (Start == End)
|
|
|
|
Start = CurStructOffset + Ctx.toCharUnitsFromBits(FStartInBits);
|
|
|
|
End = CurStructOffset + Ctx.toCharUnitsFromBits(RoundedFEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
CharUnits Start = CharUnits::Zero(), End = CharUnits::Zero();
|
|
|
|
};
|
|
|
|
|
|
|
|
// This function creates the mangled name of a special function of a non-trivial
|
|
|
|
// C struct. Since there is no ODR in C, the function is mangled based on the
|
|
|
|
// struct contents and not the name. The mangled name has the following
|
|
|
|
// structure:
|
|
|
|
//
|
|
|
|
// <function-name> ::= <prefix> <alignment-info> "_" <struct-field-info>
|
|
|
|
// <prefix> ::= "__destructor_" | "__default_constructor_" |
|
|
|
|
// "__copy_constructor_" | "__move_constructor_" |
|
|
|
|
// "__copy_assignment_" | "__move_assignment_"
|
|
|
|
// <alignment-info> ::= <dst-alignment> ["_" <src-alignment>]
|
|
|
|
// <struct-field-info> ::= <field-info>+
|
|
|
|
// <field-info> ::= <struct-or-scalar-field-info> | <array-field-info>
|
2019-03-29 01:01:20 +08:00
|
|
|
// <struct-or-scalar-field-info> ::= "_S" <struct-field-info> |
|
|
|
|
// <strong-field-info> | <trivial-field-info>
|
2018-02-28 15:15:55 +08:00
|
|
|
// <array-field-info> ::= "_AB" <array-offset> "s" <element-size> "n"
|
|
|
|
// <num-elements> <innermost-element-info> "_AE"
|
|
|
|
// <innermost-element-info> ::= <struct-or-scalar-field-info>
|
|
|
|
// <strong-field-info> ::= "_s" ["b"] ["v"] <field-offset>
|
|
|
|
// <trivial-field-info> ::= "_t" ["v"] <field-offset> "_" <field-size>
|
|
|
|
|
|
|
|
template <class Derived> struct GenFuncNameBase {
|
|
|
|
std::string getVolatileOffsetStr(bool IsVolatile, CharUnits Offset) {
|
|
|
|
std::string S;
|
|
|
|
if (IsVolatile)
|
|
|
|
S = "v";
|
|
|
|
S += llvm::to_string(Offset.getQuantity());
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitARCStrong(QualType FT, const FieldDecl *FD,
|
|
|
|
CharUnits CurStructOffset) {
|
|
|
|
appendStr("_s");
|
|
|
|
if (FT->isBlockPointerType())
|
|
|
|
appendStr("b");
|
|
|
|
CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
|
|
|
|
appendStr(getVolatileOffsetStr(FT.isVolatileQualified(), FieldOffset));
|
|
|
|
}
|
|
|
|
|
2018-03-20 01:38:40 +08:00
|
|
|
void visitARCWeak(QualType FT, const FieldDecl *FD,
|
|
|
|
CharUnits CurStructOffset) {
|
|
|
|
appendStr("_w");
|
|
|
|
CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
|
|
|
|
appendStr(getVolatileOffsetStr(FT.isVolatileQualified(), FieldOffset));
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void visitStruct(QualType QT, const FieldDecl *FD,
|
|
|
|
CharUnits CurStructOffset) {
|
|
|
|
CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
|
2019-03-29 01:01:20 +08:00
|
|
|
appendStr("_S");
|
2018-02-28 15:15:55 +08:00
|
|
|
asDerived().visitStructFields(QT, FieldOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class FieldKind>
|
2018-04-18 03:05:17 +08:00
|
|
|
void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
|
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset) {
|
2018-02-28 15:15:55 +08:00
|
|
|
// String for non-volatile trivial fields is emitted when
|
|
|
|
// flushTrivialFields is called.
|
|
|
|
if (!FK)
|
2018-04-18 03:05:17 +08:00
|
|
|
return asDerived().visitTrivial(QualType(AT, 0), FD, CurStructOffset);
|
2018-02-28 15:15:55 +08:00
|
|
|
|
2018-10-02 09:00:44 +08:00
|
|
|
asDerived().flushTrivialFields();
|
2018-02-28 15:15:55 +08:00
|
|
|
CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
|
|
|
|
ASTContext &Ctx = asDerived().getContext();
|
2018-04-18 03:05:17 +08:00
|
|
|
const ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
|
|
|
|
unsigned NumElts = Ctx.getConstantArrayElementCount(CAT);
|
|
|
|
QualType EltTy = Ctx.getBaseElementType(CAT);
|
2018-02-28 15:15:55 +08:00
|
|
|
CharUnits EltSize = Ctx.getTypeSizeInChars(EltTy);
|
|
|
|
appendStr("_AB" + llvm::to_string(FieldOffset.getQuantity()) + "s" +
|
|
|
|
llvm::to_string(EltSize.getQuantity()) + "n" +
|
|
|
|
llvm::to_string(NumElts));
|
2018-04-18 03:05:17 +08:00
|
|
|
EltTy = IsVolatile ? EltTy.withVolatile() : EltTy;
|
|
|
|
asDerived().visitWithKind(FK, EltTy, nullptr, FieldOffset);
|
2018-02-28 15:15:55 +08:00
|
|
|
appendStr("_AE");
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendStr(StringRef Str) { Name += Str; }
|
|
|
|
|
|
|
|
std::string getName(QualType QT, bool IsVolatile) {
|
|
|
|
QT = IsVolatile ? QT.withVolatile() : QT;
|
|
|
|
asDerived().visitStructFields(QT, CharUnits::Zero());
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Derived &asDerived() { return static_cast<Derived &>(*this); }
|
|
|
|
|
|
|
|
std::string Name;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Derived>
|
|
|
|
struct GenUnaryFuncName : StructVisitor<Derived>, GenFuncNameBase<Derived> {
|
|
|
|
GenUnaryFuncName(StringRef Prefix, CharUnits DstAlignment, ASTContext &Ctx)
|
|
|
|
: StructVisitor<Derived>(Ctx) {
|
|
|
|
this->appendStr(Prefix);
|
|
|
|
this->appendStr(llvm::to_string(DstAlignment.getQuantity()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper function to create a null constant.
|
|
|
|
static llvm::Constant *getNullForVariable(Address Addr) {
|
|
|
|
llvm::Type *Ty = Addr.getElementType();
|
|
|
|
return llvm::ConstantPointerNull::get(cast<llvm::PointerType>(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool IsMove>
|
|
|
|
struct GenBinaryFuncName : CopyStructVisitor<GenBinaryFuncName<IsMove>, IsMove>,
|
|
|
|
GenFuncNameBase<GenBinaryFuncName<IsMove>> {
|
|
|
|
|
|
|
|
GenBinaryFuncName(StringRef Prefix, CharUnits DstAlignment,
|
|
|
|
CharUnits SrcAlignment, ASTContext &Ctx)
|
|
|
|
: CopyStructVisitor<GenBinaryFuncName<IsMove>, IsMove>(Ctx) {
|
|
|
|
this->appendStr(Prefix);
|
|
|
|
this->appendStr(llvm::to_string(DstAlignment.getQuantity()));
|
|
|
|
this->appendStr("_" + llvm::to_string(SrcAlignment.getQuantity()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void flushTrivialFields() {
|
|
|
|
if (this->Start == this->End)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->appendStr("_t" + llvm::to_string(this->Start.getQuantity()) + "w" +
|
|
|
|
llvm::to_string((this->End - this->Start).getQuantity()));
|
|
|
|
|
|
|
|
this->Start = this->End = CharUnits::Zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitVolatileTrivial(QualType FT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset) {
|
2018-02-28 15:15:55 +08:00
|
|
|
// Because volatile fields can be bit-fields and are individually copied,
|
|
|
|
// their offset and width are in bits.
|
|
|
|
uint64_t OffsetInBits =
|
2019-03-29 08:23:17 +08:00
|
|
|
this->Ctx.toBits(CurStructOffset) + this->getFieldOffsetInBits(FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
this->appendStr("_tv" + llvm::to_string(OffsetInBits) + "w" +
|
2018-04-17 04:23:52 +08:00
|
|
|
llvm::to_string(getFieldSize(FD, FT, this->Ctx)));
|
2018-02-28 15:15:55 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GenDefaultInitializeFuncName
|
|
|
|
: GenUnaryFuncName<GenDefaultInitializeFuncName>,
|
|
|
|
DefaultInitializedTypeVisitor<GenDefaultInitializeFuncName> {
|
2018-04-18 03:05:17 +08:00
|
|
|
using Super = DefaultInitializedTypeVisitor<GenDefaultInitializeFuncName>;
|
2018-02-28 15:15:55 +08:00
|
|
|
GenDefaultInitializeFuncName(CharUnits DstAlignment, ASTContext &Ctx)
|
|
|
|
: GenUnaryFuncName<GenDefaultInitializeFuncName>("__default_constructor_",
|
|
|
|
DstAlignment, Ctx) {}
|
2018-04-18 03:05:17 +08:00
|
|
|
void visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT,
|
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset) {
|
|
|
|
if (const auto *AT = getContext().getAsArrayType(FT)) {
|
|
|
|
visitArray(PDIK, AT, FT.isVolatileQualified(), FD, CurStructOffset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Super::visitWithKind(PDIK, FT, FD, CurStructOffset);
|
|
|
|
}
|
2018-02-28 15:15:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GenDestructorFuncName : GenUnaryFuncName<GenDestructorFuncName>,
|
|
|
|
DestructedTypeVisitor<GenDestructorFuncName> {
|
2018-04-18 03:05:17 +08:00
|
|
|
using Super = DestructedTypeVisitor<GenDestructorFuncName>;
|
2018-08-10 23:09:24 +08:00
|
|
|
GenDestructorFuncName(const char *Prefix, CharUnits DstAlignment,
|
|
|
|
ASTContext &Ctx)
|
2019-03-29 08:23:17 +08:00
|
|
|
: GenUnaryFuncName<GenDestructorFuncName>(Prefix, DstAlignment, Ctx) {}
|
2018-04-18 03:05:17 +08:00
|
|
|
void visitWithKind(QualType::DestructionKind DK, QualType FT,
|
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset) {
|
|
|
|
if (const auto *AT = getContext().getAsArrayType(FT)) {
|
|
|
|
visitArray(DK, AT, FT.isVolatileQualified(), FD, CurStructOffset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Super::visitWithKind(DK, FT, FD, CurStructOffset);
|
|
|
|
}
|
2018-02-28 15:15:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper function that creates CGFunctionInfo for an N-ary special function.
|
|
|
|
template <size_t N>
|
|
|
|
static const CGFunctionInfo &getFunctionInfo(CodeGenModule &CGM,
|
|
|
|
FunctionArgList &Args) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
llvm::SmallVector<ImplicitParamDecl *, N> Params;
|
|
|
|
QualType ParamTy = Ctx.getPointerType(Ctx.VoidPtrTy);
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < N; ++I)
|
|
|
|
Params.push_back(ImplicitParamDecl::Create(
|
|
|
|
Ctx, nullptr, SourceLocation(), &Ctx.Idents.get(ValNameStr[I]), ParamTy,
|
|
|
|
ImplicitParamDecl::Other));
|
|
|
|
|
|
|
|
for (auto &P : Params)
|
|
|
|
Args.push_back(P);
|
|
|
|
|
|
|
|
return CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Template classes that are used as bases for classes that emit special
|
|
|
|
// functions.
|
|
|
|
template <class Derived> struct GenFuncBase {
|
|
|
|
template <size_t N>
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitStruct(QualType FT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-02-28 15:15:55 +08:00
|
|
|
std::array<Address, N> Addrs) {
|
|
|
|
this->asDerived().callSpecialFunction(
|
2019-03-29 08:23:17 +08:00
|
|
|
FT, CurStructOffset + asDerived().getFieldOffset(FD), Addrs);
|
2018-02-28 15:15:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class FieldKind, size_t N>
|
2018-04-18 03:05:17 +08:00
|
|
|
void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
|
2019-03-29 08:23:17 +08:00
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-04-18 03:05:17 +08:00
|
|
|
std::array<Address, N> Addrs) {
|
2018-02-28 15:15:55 +08:00
|
|
|
// Non-volatile trivial fields are copied when flushTrivialFields is called.
|
|
|
|
if (!FK)
|
2019-03-29 08:23:17 +08:00
|
|
|
return asDerived().visitTrivial(QualType(AT, 0), FD, CurStructOffset,
|
2018-04-18 03:05:17 +08:00
|
|
|
Addrs);
|
2018-02-28 15:15:55 +08:00
|
|
|
|
2018-10-02 09:00:44 +08:00
|
|
|
asDerived().flushTrivialFields(Addrs);
|
2018-02-28 15:15:55 +08:00
|
|
|
CodeGenFunction &CGF = *this->CGF;
|
|
|
|
ASTContext &Ctx = CGF.getContext();
|
|
|
|
|
|
|
|
// Compute the end address.
|
|
|
|
QualType BaseEltQT;
|
|
|
|
std::array<Address, N> StartAddrs = Addrs;
|
|
|
|
for (unsigned I = 0; I < N; ++I)
|
2019-03-29 08:23:17 +08:00
|
|
|
StartAddrs[I] = getAddrWithOffset(Addrs[I], CurStructOffset, FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
Address DstAddr = StartAddrs[DstIdx];
|
2018-04-18 03:05:17 +08:00
|
|
|
llvm::Value *NumElts = CGF.emitArrayLength(AT, BaseEltQT, DstAddr);
|
2018-02-28 15:15:55 +08:00
|
|
|
unsigned BaseEltSize = Ctx.getTypeSizeInChars(BaseEltQT).getQuantity();
|
|
|
|
llvm::Value *BaseEltSizeVal =
|
|
|
|
llvm::ConstantInt::get(NumElts->getType(), BaseEltSize);
|
|
|
|
llvm::Value *SizeInBytes =
|
|
|
|
CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
|
|
|
|
Address BC = CGF.Builder.CreateBitCast(DstAddr, CGF.CGM.Int8PtrTy);
|
|
|
|
llvm::Value *DstArrayEnd =
|
|
|
|
CGF.Builder.CreateInBoundsGEP(BC.getPointer(), SizeInBytes);
|
|
|
|
DstArrayEnd = CGF.Builder.CreateBitCast(DstArrayEnd, CGF.CGM.Int8PtrPtrTy,
|
|
|
|
"dstarray.end");
|
|
|
|
llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
|
|
|
|
|
|
|
|
// Create the header block and insert the phi instructions.
|
|
|
|
llvm::BasicBlock *HeaderBB = CGF.createBasicBlock("loop.header");
|
|
|
|
CGF.EmitBlock(HeaderBB);
|
|
|
|
llvm::PHINode *PHIs[N];
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < N; ++I) {
|
|
|
|
PHIs[I] = CGF.Builder.CreatePHI(CGF.CGM.Int8PtrPtrTy, 2, "addr.cur");
|
|
|
|
PHIs[I]->addIncoming(StartAddrs[I].getPointer(), PreheaderBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the exit and loop body blocks.
|
|
|
|
llvm::BasicBlock *ExitBB = CGF.createBasicBlock("loop.exit");
|
|
|
|
llvm::BasicBlock *LoopBB = CGF.createBasicBlock("loop.body");
|
|
|
|
|
|
|
|
// Emit the comparison and conditional branch instruction that jumps to
|
|
|
|
// either the exit or the loop body.
|
|
|
|
llvm::Value *Done =
|
|
|
|
CGF.Builder.CreateICmpEQ(PHIs[DstIdx], DstArrayEnd, "done");
|
|
|
|
CGF.Builder.CreateCondBr(Done, ExitBB, LoopBB);
|
|
|
|
|
|
|
|
// Visit the element of the array in the loop body.
|
|
|
|
CGF.EmitBlock(LoopBB);
|
2018-04-18 03:05:17 +08:00
|
|
|
QualType EltQT = AT->getElementType();
|
2018-02-28 15:15:55 +08:00
|
|
|
CharUnits EltSize = Ctx.getTypeSizeInChars(EltQT);
|
|
|
|
std::array<Address, N> NewAddrs = Addrs;
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < N; ++I)
|
|
|
|
NewAddrs[I] = Address(
|
|
|
|
PHIs[I], StartAddrs[I].getAlignment().alignmentAtOffset(EltSize));
|
|
|
|
|
2018-04-18 03:05:17 +08:00
|
|
|
EltQT = IsVolatile ? EltQT.withVolatile() : EltQT;
|
|
|
|
this->asDerived().visitWithKind(FK, EltQT, nullptr, CharUnits::Zero(),
|
|
|
|
NewAddrs);
|
2018-02-28 15:15:55 +08:00
|
|
|
|
|
|
|
LoopBB = CGF.Builder.GetInsertBlock();
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < N; ++I) {
|
|
|
|
// Instrs to update the destination and source addresses.
|
|
|
|
// Update phi instructions.
|
|
|
|
NewAddrs[I] = getAddrWithOffset(NewAddrs[I], EltSize);
|
|
|
|
PHIs[I]->addIncoming(NewAddrs[I].getPointer(), LoopBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert an unconditional branch to the header block.
|
|
|
|
CGF.Builder.CreateBr(HeaderBB);
|
|
|
|
CGF.EmitBlock(ExitBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return an address with the specified offset from the passed address.
|
|
|
|
Address getAddrWithOffset(Address Addr, CharUnits Offset) {
|
|
|
|
assert(Addr.isValid() && "invalid address");
|
|
|
|
if (Offset.getQuantity() == 0)
|
|
|
|
return Addr;
|
|
|
|
Addr = CGF->Builder.CreateBitCast(Addr, CGF->CGM.Int8PtrTy);
|
2019-02-10 06:22:28 +08:00
|
|
|
Addr = CGF->Builder.CreateConstInBoundsGEP(Addr, Offset.getQuantity());
|
2018-02-28 15:15:55 +08:00
|
|
|
return CGF->Builder.CreateBitCast(Addr, CGF->CGM.Int8PtrPtrTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
Address getAddrWithOffset(Address Addr, CharUnits StructFieldOffset,
|
|
|
|
const FieldDecl *FD) {
|
|
|
|
return getAddrWithOffset(Addr, StructFieldOffset +
|
|
|
|
asDerived().getFieldOffset(FD));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
llvm::Function *
|
|
|
|
getFunction(StringRef FuncName, QualType QT, std::array<Address, N> Addrs,
|
|
|
|
std::array<CharUnits, N> Alignments, CodeGenModule &CGM) {
|
|
|
|
// If the special function already exists in the module, return it.
|
|
|
|
if (llvm::Function *F = CGM.getModule().getFunction(FuncName)) {
|
|
|
|
bool WrongType = false;
|
|
|
|
if (!F->getReturnType()->isVoidTy())
|
|
|
|
WrongType = true;
|
|
|
|
else {
|
|
|
|
for (const llvm::Argument &Arg : F->args())
|
|
|
|
if (Arg.getType() != CGM.Int8PtrPtrTy)
|
|
|
|
WrongType = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WrongType) {
|
|
|
|
std::string FuncName = F->getName();
|
|
|
|
SourceLocation Loc = QT->castAs<RecordType>()->getDecl()->getLocation();
|
|
|
|
CGM.Error(Loc, "special function " + FuncName +
|
|
|
|
" for non-trivial C struct has incorrect type");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
FunctionArgList Args;
|
|
|
|
const CGFunctionInfo &FI = getFunctionInfo<N>(CGM, Args);
|
|
|
|
llvm::FunctionType *FuncTy = CGM.getTypes().GetFunctionType(FI);
|
|
|
|
llvm::Function *F =
|
|
|
|
llvm::Function::Create(FuncTy, llvm::GlobalValue::LinkOnceODRLinkage,
|
|
|
|
FuncName, &CGM.getModule());
|
|
|
|
F->setVisibility(llvm::GlobalValue::HiddenVisibility);
|
2018-11-13 23:48:08 +08:00
|
|
|
CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, F);
|
2018-02-28 15:15:55 +08:00
|
|
|
CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F);
|
|
|
|
IdentifierInfo *II = &Ctx.Idents.get(FuncName);
|
|
|
|
FunctionDecl *FD = FunctionDecl::Create(
|
|
|
|
Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
|
2018-11-11 08:56:15 +08:00
|
|
|
II, Ctx.getFunctionType(Ctx.VoidTy, llvm::None, {}), nullptr,
|
|
|
|
SC_PrivateExtern, false, false);
|
2018-02-28 15:15:55 +08:00
|
|
|
CodeGenFunction NewCGF(CGM);
|
|
|
|
setCGF(&NewCGF);
|
|
|
|
CGF->StartFunction(FD, Ctx.VoidTy, F, FI, Args);
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < N; ++I) {
|
|
|
|
llvm::Value *V = CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[I]));
|
|
|
|
Addrs[I] = Address(V, Alignments[I]);
|
|
|
|
}
|
|
|
|
|
|
|
|
asDerived().visitStructFields(QT, CharUnits::Zero(), Addrs);
|
|
|
|
CGF->FinishFunction();
|
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
void callFunc(StringRef FuncName, QualType QT, std::array<Address, N> Addrs,
|
|
|
|
CodeGenFunction &CallerCGF) {
|
|
|
|
std::array<CharUnits, N> Alignments;
|
|
|
|
llvm::Value *Ptrs[N];
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < N; ++I) {
|
|
|
|
Alignments[I] = Addrs[I].getAlignment();
|
|
|
|
Ptrs[I] =
|
|
|
|
CallerCGF.Builder.CreateBitCast(Addrs[I], CallerCGF.CGM.Int8PtrPtrTy)
|
|
|
|
.getPointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (llvm::Function *F =
|
|
|
|
getFunction(FuncName, QT, Addrs, Alignments, CallerCGF.CGM))
|
|
|
|
CallerCGF.EmitNounwindRuntimeCall(F, Ptrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Derived &asDerived() { return static_cast<Derived &>(*this); }
|
|
|
|
|
|
|
|
void setCGF(CodeGenFunction *F) { CGF = F; }
|
|
|
|
|
|
|
|
CodeGenFunction *CGF = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Derived, bool IsMove>
|
|
|
|
struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
|
|
|
|
GenFuncBase<Derived> {
|
|
|
|
GenBinaryFunc(ASTContext &Ctx) : CopyStructVisitor<Derived, IsMove>(Ctx) {}
|
|
|
|
|
|
|
|
void flushTrivialFields(std::array<Address, 2> Addrs) {
|
|
|
|
CharUnits Size = this->End - this->Start;
|
|
|
|
|
|
|
|
if (Size.getQuantity() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], this->Start);
|
|
|
|
Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], this->Start);
|
|
|
|
|
|
|
|
// Emit memcpy.
|
|
|
|
if (Size.getQuantity() >= 16 || !llvm::isPowerOf2_32(Size.getQuantity())) {
|
|
|
|
llvm::Value *SizeVal =
|
|
|
|
llvm::ConstantInt::get(this->CGF->SizeTy, Size.getQuantity());
|
|
|
|
DstAddr =
|
|
|
|
this->CGF->Builder.CreateElementBitCast(DstAddr, this->CGF->Int8Ty);
|
|
|
|
SrcAddr =
|
|
|
|
this->CGF->Builder.CreateElementBitCast(SrcAddr, this->CGF->Int8Ty);
|
|
|
|
this->CGF->Builder.CreateMemCpy(DstAddr, SrcAddr, SizeVal, false);
|
|
|
|
} else {
|
|
|
|
llvm::Type *Ty = llvm::Type::getIntNTy(
|
|
|
|
this->CGF->getLLVMContext(),
|
|
|
|
Size.getQuantity() * this->CGF->getContext().getCharWidth());
|
|
|
|
DstAddr = this->CGF->Builder.CreateElementBitCast(DstAddr, Ty);
|
|
|
|
SrcAddr = this->CGF->Builder.CreateElementBitCast(SrcAddr, Ty);
|
|
|
|
llvm::Value *SrcVal = this->CGF->Builder.CreateLoad(SrcAddr, false);
|
|
|
|
this->CGF->Builder.CreateStore(SrcVal, DstAddr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->Start = this->End = CharUnits::Zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ts>
|
|
|
|
void visitVolatileTrivial(QualType FT, const FieldDecl *FD, CharUnits Offset,
|
|
|
|
std::array<Address, 2> Addrs) {
|
2018-04-17 04:23:52 +08:00
|
|
|
LValue DstLV, SrcLV;
|
|
|
|
if (FD) {
|
|
|
|
QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0);
|
|
|
|
llvm::PointerType *PtrTy = this->CGF->ConvertType(RT)->getPointerTo();
|
|
|
|
Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], Offset);
|
|
|
|
LValue DstBase = this->CGF->MakeAddrLValue(
|
|
|
|
this->CGF->Builder.CreateBitCast(DstAddr, PtrTy), FT);
|
|
|
|
DstLV = this->CGF->EmitLValueForField(DstBase, FD);
|
|
|
|
Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], Offset);
|
|
|
|
LValue SrcBase = this->CGF->MakeAddrLValue(
|
|
|
|
this->CGF->Builder.CreateBitCast(SrcAddr, PtrTy), FT);
|
|
|
|
SrcLV = this->CGF->EmitLValueForField(SrcBase, FD);
|
|
|
|
} else {
|
|
|
|
llvm::PointerType *Ty = this->CGF->ConvertType(FT)->getPointerTo();
|
|
|
|
Address DstAddr = this->CGF->Builder.CreateBitCast(Addrs[DstIdx], Ty);
|
|
|
|
Address SrcAddr = this->CGF->Builder.CreateBitCast(Addrs[SrcIdx], Ty);
|
|
|
|
DstLV = this->CGF->MakeAddrLValue(DstAddr, FT);
|
|
|
|
SrcLV = this->CGF->MakeAddrLValue(SrcAddr, FT);
|
|
|
|
}
|
2018-02-28 15:15:55 +08:00
|
|
|
RValue SrcVal = this->CGF->EmitLoadOfLValue(SrcLV, SourceLocation());
|
|
|
|
this->CGF->EmitStoreThroughLValue(SrcVal, DstLV);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// These classes that emit the special functions for a non-trivial struct.
|
|
|
|
struct GenDestructor : StructVisitor<GenDestructor>,
|
|
|
|
GenFuncBase<GenDestructor>,
|
|
|
|
DestructedTypeVisitor<GenDestructor> {
|
2018-04-18 03:05:17 +08:00
|
|
|
using Super = DestructedTypeVisitor<GenDestructor>;
|
2018-02-28 15:15:55 +08:00
|
|
|
GenDestructor(ASTContext &Ctx) : StructVisitor<GenDestructor>(Ctx) {}
|
2018-04-18 03:05:17 +08:00
|
|
|
|
|
|
|
void visitWithKind(QualType::DestructionKind DK, QualType FT,
|
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset,
|
|
|
|
std::array<Address, 1> Addrs) {
|
|
|
|
if (const auto *AT = getContext().getAsArrayType(FT)) {
|
|
|
|
visitArray(DK, AT, FT.isVolatileQualified(), FD, CurStructOffset, Addrs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Super::visitWithKind(DK, FT, FD, CurStructOffset, Addrs);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void visitARCStrong(QualType QT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset, std::array<Address, 1> Addrs) {
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->destroyARCStrongImprecise(
|
2019-03-29 08:23:17 +08:00
|
|
|
*CGF, getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD), QT);
|
2018-02-28 15:15:55 +08:00
|
|
|
}
|
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-03-20 01:38:40 +08:00
|
|
|
std::array<Address, 1> Addrs) {
|
|
|
|
CGF->destroyARCWeak(
|
2019-03-29 08:23:17 +08:00
|
|
|
*CGF, getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD), QT);
|
2018-03-20 01:38:40 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void callSpecialFunction(QualType FT, CharUnits Offset,
|
|
|
|
std::array<Address, 1> Addrs) {
|
|
|
|
CGF->callCStructDestructor(
|
|
|
|
CGF->MakeAddrLValue(getAddrWithOffset(Addrs[DstIdx], Offset), FT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GenDefaultInitialize
|
|
|
|
: StructVisitor<GenDefaultInitialize>,
|
|
|
|
GenFuncBase<GenDefaultInitialize>,
|
|
|
|
DefaultInitializedTypeVisitor<GenDefaultInitialize> {
|
2018-04-18 03:05:17 +08:00
|
|
|
using Super = DefaultInitializedTypeVisitor<GenDefaultInitialize>;
|
2018-02-28 15:15:55 +08:00
|
|
|
typedef GenFuncBase<GenDefaultInitialize> GenFuncBaseTy;
|
2018-04-18 03:05:17 +08:00
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
GenDefaultInitialize(ASTContext &Ctx)
|
|
|
|
: StructVisitor<GenDefaultInitialize>(Ctx) {}
|
|
|
|
|
2018-04-18 03:05:17 +08:00
|
|
|
void visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT,
|
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset,
|
|
|
|
std::array<Address, 1> Addrs) {
|
|
|
|
if (const auto *AT = getContext().getAsArrayType(FT)) {
|
|
|
|
visitArray(PDIK, AT, FT.isVolatileQualified(), FD, CurStructOffset,
|
|
|
|
Addrs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Super::visitWithKind(PDIK, FT, FD, CurStructOffset, Addrs);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void visitARCStrong(QualType QT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset, std::array<Address, 1> Addrs) {
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->EmitNullInitialization(
|
2019-03-29 08:23:17 +08:00
|
|
|
getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD), QT);
|
2018-02-28 15:15:55 +08:00
|
|
|
}
|
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-03-20 01:38:40 +08:00
|
|
|
std::array<Address, 1> Addrs) {
|
|
|
|
CGF->EmitNullInitialization(
|
2019-03-29 08:23:17 +08:00
|
|
|
getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD), QT);
|
2018-03-20 01:38:40 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
template <class FieldKind, size_t... Is>
|
2018-04-18 03:05:17 +08:00
|
|
|
void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
|
2019-03-29 08:23:17 +08:00
|
|
|
const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-04-18 03:05:17 +08:00
|
|
|
std::array<Address, 1> Addrs) {
|
2018-02-28 15:15:55 +08:00
|
|
|
if (!FK)
|
2019-03-29 08:23:17 +08:00
|
|
|
return visitTrivial(QualType(AT, 0), FD, CurStructOffset, Addrs);
|
2018-02-28 15:15:55 +08:00
|
|
|
|
|
|
|
ASTContext &Ctx = getContext();
|
2018-04-18 03:05:17 +08:00
|
|
|
CharUnits Size = Ctx.getTypeSizeInChars(QualType(AT, 0));
|
|
|
|
QualType EltTy = Ctx.getBaseElementType(QualType(AT, 0));
|
2018-02-28 15:15:55 +08:00
|
|
|
|
|
|
|
if (Size < CharUnits::fromQuantity(16) || EltTy->getAs<RecordType>()) {
|
2019-03-29 08:23:17 +08:00
|
|
|
GenFuncBaseTy::visitArray(FK, AT, IsVolatile, FD, CurStructOffset, Addrs);
|
2018-02-28 15:15:55 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Constant *SizeVal = CGF->Builder.getInt64(Size.getQuantity());
|
2019-03-29 08:23:17 +08:00
|
|
|
Address DstAddr = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
Address Loc = CGF->Builder.CreateElementBitCast(DstAddr, CGF->Int8Ty);
|
|
|
|
CGF->Builder.CreateMemSet(Loc, CGF->Builder.getInt8(0), SizeVal,
|
2018-04-18 03:05:17 +08:00
|
|
|
IsVolatile);
|
2018-02-28 15:15:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void callSpecialFunction(QualType FT, CharUnits Offset,
|
|
|
|
std::array<Address, 1> Addrs) {
|
|
|
|
CGF->callCStructDefaultConstructor(
|
|
|
|
CGF->MakeAddrLValue(getAddrWithOffset(Addrs[DstIdx], Offset), FT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GenCopyConstructor : GenBinaryFunc<GenCopyConstructor, false> {
|
|
|
|
GenCopyConstructor(ASTContext &Ctx)
|
|
|
|
: GenBinaryFunc<GenCopyConstructor, false>(Ctx) {}
|
|
|
|
|
|
|
|
void visitARCStrong(QualType QT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset, std::array<Address, 2> Addrs) {
|
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
llvm::Value *SrcVal = CGF->EmitLoadOfScalar(
|
|
|
|
Addrs[SrcIdx], QT.isVolatileQualified(), QT, SourceLocation());
|
|
|
|
llvm::Value *Val = CGF->EmitARCRetain(QT, SrcVal);
|
|
|
|
CGF->EmitStoreOfScalar(Val, CGF->MakeAddrLValue(Addrs[DstIdx], QT), true);
|
|
|
|
}
|
2018-03-20 01:38:40 +08:00
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-03-20 01:38:40 +08:00
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:17 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-03-20 01:38:40 +08:00
|
|
|
CGF->EmitARCCopyWeak(Addrs[DstIdx], Addrs[SrcIdx]);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void callSpecialFunction(QualType FT, CharUnits Offset,
|
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:20 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->callCStructCopyConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),
|
|
|
|
CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GenMoveConstructor : GenBinaryFunc<GenMoveConstructor, true> {
|
|
|
|
GenMoveConstructor(ASTContext &Ctx)
|
|
|
|
: GenBinaryFunc<GenMoveConstructor, true>(Ctx) {}
|
|
|
|
|
|
|
|
void visitARCStrong(QualType QT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset, std::array<Address, 2> Addrs) {
|
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
LValue SrcLV = CGF->MakeAddrLValue(Addrs[SrcIdx], QT);
|
|
|
|
llvm::Value *SrcVal =
|
|
|
|
CGF->EmitLoadOfLValue(SrcLV, SourceLocation()).getScalarVal();
|
2019-12-04 07:17:01 +08:00
|
|
|
CGF->EmitStoreOfScalar(getNullForVariable(SrcLV.getAddress(*CGF)), SrcLV);
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->EmitStoreOfScalar(SrcVal, CGF->MakeAddrLValue(Addrs[DstIdx], QT),
|
|
|
|
/* isInitialization */ true);
|
|
|
|
}
|
2018-03-20 01:38:40 +08:00
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-03-20 01:38:40 +08:00
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:17 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-03-20 01:38:40 +08:00
|
|
|
CGF->EmitARCMoveWeak(Addrs[DstIdx], Addrs[SrcIdx]);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void callSpecialFunction(QualType FT, CharUnits Offset,
|
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:20 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->callCStructMoveConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),
|
|
|
|
CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GenCopyAssignment : GenBinaryFunc<GenCopyAssignment, false> {
|
|
|
|
GenCopyAssignment(ASTContext &Ctx)
|
|
|
|
: GenBinaryFunc<GenCopyAssignment, false>(Ctx) {}
|
|
|
|
|
|
|
|
void visitARCStrong(QualType QT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset, std::array<Address, 2> Addrs) {
|
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
llvm::Value *SrcVal = CGF->EmitLoadOfScalar(
|
|
|
|
Addrs[SrcIdx], QT.isVolatileQualified(), QT, SourceLocation());
|
|
|
|
CGF->EmitARCStoreStrong(CGF->MakeAddrLValue(Addrs[DstIdx], QT), SrcVal,
|
|
|
|
false);
|
|
|
|
}
|
2018-03-20 01:38:40 +08:00
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-03-20 01:38:40 +08:00
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:17 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-03-20 01:38:40 +08:00
|
|
|
CGF->emitARCCopyAssignWeak(QT, Addrs[DstIdx], Addrs[SrcIdx]);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void callSpecialFunction(QualType FT, CharUnits Offset,
|
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:20 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->callCStructCopyAssignmentOperator(
|
|
|
|
CGF->MakeAddrLValue(Addrs[DstIdx], FT),
|
|
|
|
CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GenMoveAssignment : GenBinaryFunc<GenMoveAssignment, true> {
|
|
|
|
GenMoveAssignment(ASTContext &Ctx)
|
|
|
|
: GenBinaryFunc<GenMoveAssignment, true>(Ctx) {}
|
|
|
|
|
|
|
|
void visitARCStrong(QualType QT, const FieldDecl *FD,
|
2019-03-29 08:23:17 +08:00
|
|
|
CharUnits CurStructOffset, std::array<Address, 2> Addrs) {
|
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-02-28 15:15:55 +08:00
|
|
|
LValue SrcLV = CGF->MakeAddrLValue(Addrs[SrcIdx], QT);
|
|
|
|
llvm::Value *SrcVal =
|
|
|
|
CGF->EmitLoadOfLValue(SrcLV, SourceLocation()).getScalarVal();
|
2019-12-04 07:17:01 +08:00
|
|
|
CGF->EmitStoreOfScalar(getNullForVariable(SrcLV.getAddress(*CGF)), SrcLV);
|
2018-02-28 15:15:55 +08:00
|
|
|
LValue DstLV = CGF->MakeAddrLValue(Addrs[DstIdx], QT);
|
|
|
|
llvm::Value *DstVal =
|
|
|
|
CGF->EmitLoadOfLValue(DstLV, SourceLocation()).getScalarVal();
|
|
|
|
CGF->EmitStoreOfScalar(SrcVal, DstLV);
|
|
|
|
CGF->EmitARCRelease(DstVal, ARCImpreciseLifetime);
|
|
|
|
}
|
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStructOffset,
|
2018-03-20 01:38:40 +08:00
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:17 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStructOffset, FD);
|
2018-03-20 01:38:40 +08:00
|
|
|
CGF->emitARCMoveAssignWeak(QT, Addrs[DstIdx], Addrs[SrcIdx]);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void callSpecialFunction(QualType FT, CharUnits Offset,
|
|
|
|
std::array<Address, 2> Addrs) {
|
2019-03-29 08:23:20 +08:00
|
|
|
Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
|
|
|
|
Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
|
2018-02-28 15:15:55 +08:00
|
|
|
CGF->callCStructMoveAssignmentOperator(
|
|
|
|
CGF->MakeAddrLValue(Addrs[DstIdx], FT),
|
|
|
|
CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void CodeGenFunction::destroyNonTrivialCStruct(CodeGenFunction &CGF,
|
|
|
|
Address Addr, QualType Type) {
|
|
|
|
CGF.callCStructDestructor(CGF.MakeAddrLValue(Addr, Type));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default-initialize a variable that is a non-trivial struct or an array of
|
|
|
|
// such structure.
|
|
|
|
void CodeGenFunction::defaultInitNonTrivialCStructVar(LValue Dst) {
|
|
|
|
GenDefaultInitialize Gen(getContext());
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr =
|
|
|
|
Builder.CreateBitCast(Dst.getAddress(*this), CGM.Int8PtrPtrTy);
|
2018-02-28 15:15:55 +08:00
|
|
|
Gen.setCGF(this);
|
|
|
|
QualType QT = Dst.getType();
|
|
|
|
QT = Dst.isVolatile() ? QT.withVolatile() : QT;
|
|
|
|
Gen.visit(QT, nullptr, CharUnits::Zero(), std::array<Address, 1>({{DstPtr}}));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class G, size_t N>
|
|
|
|
static void callSpecialFunction(G &&Gen, StringRef FuncName, QualType QT,
|
|
|
|
bool IsVolatile, CodeGenFunction &CGF,
|
|
|
|
std::array<Address, N> Addrs) {
|
2019-11-19 06:16:08 +08:00
|
|
|
auto SetArtificialLoc = ApplyDebugLocation::CreateArtificial(CGF);
|
2018-02-28 15:15:55 +08:00
|
|
|
for (unsigned I = 0; I < N; ++I)
|
|
|
|
Addrs[I] = CGF.Builder.CreateBitCast(Addrs[I], CGF.CGM.Int8PtrPtrTy);
|
|
|
|
QT = IsVolatile ? QT.withVolatile() : QT;
|
|
|
|
Gen.callFunc(FuncName, QT, Addrs, CGF);
|
|
|
|
}
|
|
|
|
|
2019-08-24 03:59:23 +08:00
|
|
|
template <size_t N> static std::array<Address, N> createNullAddressArray();
|
2019-04-11 03:57:20 +08:00
|
|
|
|
|
|
|
template <> std::array<Address, 1> createNullAddressArray() {
|
2019-04-11 14:57:12 +08:00
|
|
|
return std::array<Address, 1>({{Address(nullptr, CharUnits::Zero())}});
|
2019-04-11 03:57:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <> std::array<Address, 2> createNullAddressArray() {
|
2019-04-11 14:57:12 +08:00
|
|
|
return std::array<Address, 2>({{Address(nullptr, CharUnits::Zero()),
|
|
|
|
Address(nullptr, CharUnits::Zero())}});
|
2019-04-11 03:57:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class G, size_t N>
|
|
|
|
static llvm::Function *
|
|
|
|
getSpecialFunction(G &&Gen, StringRef FuncName, QualType QT, bool IsVolatile,
|
|
|
|
std::array<CharUnits, N> Alignments, CodeGenModule &CGM) {
|
|
|
|
QT = IsVolatile ? QT.withVolatile() : QT;
|
|
|
|
// The following call requires an array of addresses as arguments, but doesn't
|
|
|
|
// actually use them (it overwrites them with the addresses of the arguments
|
|
|
|
// of the created function).
|
|
|
|
return Gen.getFunction(FuncName, QT, createNullAddressArray<N>(), Alignments,
|
|
|
|
CGM);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
// Functions to emit calls to the special functions of a non-trivial C struct.
|
|
|
|
void CodeGenFunction::callCStructDefaultConstructor(LValue Dst) {
|
|
|
|
bool IsVolatile = Dst.isVolatile();
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr = Dst.getAddress(*this);
|
2018-02-28 15:15:55 +08:00
|
|
|
QualType QT = Dst.getType();
|
|
|
|
GenDefaultInitializeFuncName GenName(DstPtr.getAlignment(), getContext());
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
callSpecialFunction(GenDefaultInitialize(getContext()), FuncName, QT,
|
|
|
|
IsVolatile, *this, std::array<Address, 1>({{DstPtr}}));
|
|
|
|
}
|
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
std::string CodeGenFunction::getNonTrivialCopyConstructorStr(
|
|
|
|
QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx) {
|
2018-08-10 23:09:24 +08:00
|
|
|
GenBinaryFuncName<false> GenName("", Alignment, Alignment, Ctx);
|
|
|
|
return GenName.getName(QT, IsVolatile);
|
|
|
|
}
|
|
|
|
|
2019-03-29 08:23:17 +08:00
|
|
|
std::string CodeGenFunction::getNonTrivialDestructorStr(QualType QT,
|
|
|
|
CharUnits Alignment,
|
|
|
|
bool IsVolatile,
|
|
|
|
ASTContext &Ctx) {
|
2018-08-10 23:09:24 +08:00
|
|
|
GenDestructorFuncName GenName("", Alignment, Ctx);
|
|
|
|
return GenName.getName(QT, IsVolatile);
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:15:55 +08:00
|
|
|
void CodeGenFunction::callCStructDestructor(LValue Dst) {
|
|
|
|
bool IsVolatile = Dst.isVolatile();
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr = Dst.getAddress(*this);
|
2018-02-28 15:15:55 +08:00
|
|
|
QualType QT = Dst.getType();
|
2018-08-10 23:09:24 +08:00
|
|
|
GenDestructorFuncName GenName("__destructor_", DstPtr.getAlignment(),
|
|
|
|
getContext());
|
2018-02-28 15:15:55 +08:00
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
callSpecialFunction(GenDestructor(getContext()), FuncName, QT, IsVolatile,
|
|
|
|
*this, std::array<Address, 1>({{DstPtr}}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::callCStructCopyConstructor(LValue Dst, LValue Src) {
|
|
|
|
bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr = Dst.getAddress(*this), SrcPtr = Src.getAddress(*this);
|
2018-02-28 15:15:55 +08:00
|
|
|
QualType QT = Dst.getType();
|
|
|
|
GenBinaryFuncName<false> GenName("__copy_constructor_", DstPtr.getAlignment(),
|
|
|
|
SrcPtr.getAlignment(), getContext());
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
callSpecialFunction(GenCopyConstructor(getContext()), FuncName, QT,
|
|
|
|
IsVolatile, *this,
|
|
|
|
std::array<Address, 2>({{DstPtr, SrcPtr}}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::callCStructCopyAssignmentOperator(LValue Dst, LValue Src
|
|
|
|
|
|
|
|
) {
|
|
|
|
bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr = Dst.getAddress(*this), SrcPtr = Src.getAddress(*this);
|
2018-02-28 15:15:55 +08:00
|
|
|
QualType QT = Dst.getType();
|
|
|
|
GenBinaryFuncName<false> GenName("__copy_assignment_", DstPtr.getAlignment(),
|
|
|
|
SrcPtr.getAlignment(), getContext());
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
callSpecialFunction(GenCopyAssignment(getContext()), FuncName, QT, IsVolatile,
|
|
|
|
*this, std::array<Address, 2>({{DstPtr, SrcPtr}}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::callCStructMoveConstructor(LValue Dst, LValue Src) {
|
|
|
|
bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr = Dst.getAddress(*this), SrcPtr = Src.getAddress(*this);
|
2018-02-28 15:15:55 +08:00
|
|
|
QualType QT = Dst.getType();
|
|
|
|
GenBinaryFuncName<true> GenName("__move_constructor_", DstPtr.getAlignment(),
|
|
|
|
SrcPtr.getAlignment(), getContext());
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
callSpecialFunction(GenMoveConstructor(getContext()), FuncName, QT,
|
|
|
|
IsVolatile, *this,
|
|
|
|
std::array<Address, 2>({{DstPtr, SrcPtr}}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeGenFunction::callCStructMoveAssignmentOperator(LValue Dst, LValue Src
|
|
|
|
|
|
|
|
) {
|
|
|
|
bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
|
2019-12-04 07:17:01 +08:00
|
|
|
Address DstPtr = Dst.getAddress(*this), SrcPtr = Src.getAddress(*this);
|
2018-02-28 15:15:55 +08:00
|
|
|
QualType QT = Dst.getType();
|
|
|
|
GenBinaryFuncName<true> GenName("__move_assignment_", DstPtr.getAlignment(),
|
|
|
|
SrcPtr.getAlignment(), getContext());
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
callSpecialFunction(GenMoveAssignment(getContext()), FuncName, QT, IsVolatile,
|
|
|
|
*this, std::array<Address, 2>({{DstPtr, SrcPtr}}));
|
|
|
|
}
|
2019-04-11 03:57:20 +08:00
|
|
|
|
|
|
|
llvm::Function *clang::CodeGen::getNonTrivialCStructDefaultConstructor(
|
|
|
|
CodeGenModule &CGM, CharUnits DstAlignment, bool IsVolatile, QualType QT) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
GenDefaultInitializeFuncName GenName(DstAlignment, Ctx);
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
return getSpecialFunction(GenDefaultInitialize(Ctx), FuncName, QT, IsVolatile,
|
|
|
|
std::array<CharUnits, 1>({{DstAlignment}}), CGM);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *clang::CodeGen::getNonTrivialCStructCopyConstructor(
|
|
|
|
CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
|
|
|
|
bool IsVolatile, QualType QT) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
GenBinaryFuncName<false> GenName("__copy_constructor_", DstAlignment,
|
|
|
|
SrcAlignment, Ctx);
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
return getSpecialFunction(
|
|
|
|
GenCopyConstructor(Ctx), FuncName, QT, IsVolatile,
|
|
|
|
std::array<CharUnits, 2>({{DstAlignment, SrcAlignment}}), CGM);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *clang::CodeGen::getNonTrivialCStructMoveConstructor(
|
|
|
|
CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
|
|
|
|
bool IsVolatile, QualType QT) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
GenBinaryFuncName<true> GenName("__move_constructor_", DstAlignment,
|
|
|
|
SrcAlignment, Ctx);
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
return getSpecialFunction(
|
|
|
|
GenMoveConstructor(Ctx), FuncName, QT, IsVolatile,
|
|
|
|
std::array<CharUnits, 2>({{DstAlignment, SrcAlignment}}), CGM);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *clang::CodeGen::getNonTrivialCStructCopyAssignmentOperator(
|
|
|
|
CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
|
|
|
|
bool IsVolatile, QualType QT) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
GenBinaryFuncName<false> GenName("__copy_assignment_", DstAlignment,
|
|
|
|
SrcAlignment, Ctx);
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
return getSpecialFunction(
|
|
|
|
GenCopyAssignment(Ctx), FuncName, QT, IsVolatile,
|
|
|
|
std::array<CharUnits, 2>({{DstAlignment, SrcAlignment}}), CGM);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *clang::CodeGen::getNonTrivialCStructMoveAssignmentOperator(
|
|
|
|
CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
|
|
|
|
bool IsVolatile, QualType QT) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
GenBinaryFuncName<true> GenName("__move_assignment_", DstAlignment,
|
|
|
|
SrcAlignment, Ctx);
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
return getSpecialFunction(
|
|
|
|
GenMoveAssignment(Ctx), FuncName, QT, IsVolatile,
|
|
|
|
std::array<CharUnits, 2>({{DstAlignment, SrcAlignment}}), CGM);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *clang::CodeGen::getNonTrivialCStructDestructor(
|
|
|
|
CodeGenModule &CGM, CharUnits DstAlignment, bool IsVolatile, QualType QT) {
|
|
|
|
ASTContext &Ctx = CGM.getContext();
|
|
|
|
GenDestructorFuncName GenName("__destructor_", DstAlignment, Ctx);
|
|
|
|
std::string FuncName = GenName.getName(QT, IsVolatile);
|
|
|
|
return getSpecialFunction(GenDestructor(Ctx), FuncName, QT, IsVolatile,
|
|
|
|
std::array<CharUnits, 1>({{DstAlignment}}), CGM);
|
|
|
|
}
|