[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 02:57:20 PST 2023


foad created this revision.
foad added reviewers: ilya-biryukov, sammccall, dblaikie, zuban32, mpaszkowski, arsenm.
Herald added a subscriber: StephenFan.
Herald added a project: All.
foad requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

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,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 <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 +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 <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.491685.patch
Type: text/x-patch
Size: 2242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230124/ba0fb16e/attachment-0001.bin>


More information about the llvm-commits mailing list