diff --git a/llvm/include/llvm/MC/MCInstrDesc.h b/llvm/include/llvm/MC/MCInstrDesc.h --- a/llvm/include/llvm/MC/MCInstrDesc.h +++ b/llvm/include/llvm/MC/MCInstrDesc.h @@ -190,6 +190,19 @@ }; } // namespace MCID +namespace { +// An empty struct that can be used as a trailing member to prevent another +// struct from being copied or moved while still allowing aggregate +// initialization in both C++17 and C++20. +struct NonCopyableNonMovable { + NonCopyableNonMovable() = default; + NonCopyableNonMovable(const NonCopyableNonMovable&) = delete; + NonCopyableNonMovable(NonCopyableNonMovable&&) = delete; + NonCopyableNonMovable &operator=(const NonCopyableNonMovable &) = delete; + NonCopyableNonMovable &operator=(NonCopyableNonMovable &&) = delete; +}; +} // anonymous namespace + /// Describe properties that are true of each instruction in the target /// description file. This captures information about side effects, register /// use and many other things. There is one instance of this struct for each @@ -197,11 +210,6 @@ /// directly to describe itself. class MCInstrDesc { public: - // FIXME: Disable copies and moves. - // Do not allow MCInstrDescs to be copied or moved. They should only exist in - // the Insts table because they rely on knowing their own address to - // find other information elsewhere in the same table. - unsigned short Opcode; // The opcode number unsigned short NumOperands; // Num of args (may be more if variable_ops) unsigned char NumDefs; // Num of args that are definitions @@ -212,6 +220,10 @@ const MCPhysReg *ImplicitUses; // Registers implicitly read by this instr const MCPhysReg *ImplicitDefs; // Registers implicitly defined by this instr const MCOperandInfo *OpInfo; // 'NumOperands' entries about operands + // Do not allow MCInstrDescs to be copied or moved. They should only exist in + // the Insts table because they rely on knowing their own address to + // find other information elsewhere in the same table. + [[no_unique_address]] NonCopyableNonMovable NCNM{}; /// Returns the value of the specified operand constraint if /// it is present. Returns -1 if it is not present.