[PATCH] D142446: [MC] Disable copying and moving of MCInstrDescs the C++20 way

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 03:21:58 PST 2023


foad updated this revision to Diff 491694.
foad added a comment.

Remove anonymous namespace.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142446/new/

https://reviews.llvm.org/D142446

Files:
  llvm/include/llvm/MC/MCInstrDesc.h


Index: llvm/include/llvm/MC/MCInstrDesc.h
===================================================================
--- llvm/include/llvm/MC/MCInstrDesc.h
+++ llvm/include/llvm/MC/MCInstrDesc.h
@@ -190,18 +190,24 @@
 };
 } // namespace MCID
 
+// 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;
+};
+
 /// 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
 /// target instruction class, and the MachineInstr class points to this struct
 /// directly to describe itself.
-class MCInstrDesc {
+class MCInstrDesc final {
 public:
-  // FIXME: Disable copies and moves.
-  // Do not allow MCInstrDescs to be copied or moved. They should only exist in
-  // the <Target>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 +218,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 <Target>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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142446.491694.patch
Type: text/x-patch
Size: 2290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230124/208934f5/attachment.bin>


More information about the llvm-commits mailing list