use unique_ptr to avoid calling deleted move ctor

This commit is contained in:
Qingyuan Zheng 2022-05-30 23:08:50 -07:00
parent 279c28e70a
commit b6df89b470

View File

@ -358,12 +358,12 @@ public:
{ return reducedPrecisionReturn ? DecorationRelaxedPrecision : NoPrecision; } { return reducedPrecisionReturn ? DecorationRelaxedPrecision : NoPrecision; }
void setDebugLineInfo(Id fileName, int line, int column) { void setDebugLineInfo(Id fileName, int line, int column) {
lineInstruction = Instruction(OpLine); lineInstruction = std::make_unique<Instruction>(OpLine);
lineInstruction.addIdOperand(fileName); lineInstruction->addIdOperand(fileName);
lineInstruction.addImmediateOperand(line); lineInstruction->addImmediateOperand(line);
lineInstruction.addImmediateOperand(column); lineInstruction->addImmediateOperand(column);
} }
bool hasDebugLineInfo() const { return lineInstruction.getOpCode() == OpLine; } bool hasDebugLineInfo() const { return lineInstruction != nullptr; }
void setImplicitThis() { implicitThis = true; } void setImplicitThis() { implicitThis = true; }
bool hasImplicitThis() const { return implicitThis; } bool hasImplicitThis() const { return implicitThis; }
@ -382,8 +382,8 @@ public:
void dump(std::vector<unsigned int>& out) const void dump(std::vector<unsigned int>& out) const
{ {
// OpLine // OpLine
if (hasDebugLineInfo()) { if (lineInstruction != nullptr) {
lineInstruction.dump(out); lineInstruction->dump(out);
} }
// OpFunction // OpFunction
@ -404,7 +404,7 @@ protected:
Function& operator=(Function&); Function& operator=(Function&);
Module& parent; Module& parent;
Instruction lineInstruction; std::unique_ptr<Instruction> lineInstruction;
Instruction functionInstruction; Instruction functionInstruction;
std::vector<Instruction*> parameterInstructions; std::vector<Instruction*> parameterInstructions;
std::vector<Block*> blocks; std::vector<Block*> blocks;
@ -471,7 +471,7 @@ protected:
// - the OpFunction instruction // - the OpFunction instruction
// - all the OpFunctionParameter instructions // - all the OpFunctionParameter instructions
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& parent) __inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& parent)
: parent(parent), lineInstruction(OpNop), : parent(parent), lineInstruction(nullptr),
functionInstruction(id, resultType, OpFunction), implicitThis(false), functionInstruction(id, resultType, OpFunction), implicitThis(false),
reducedPrecisionReturn(false) reducedPrecisionReturn(false)
{ {