[PATCH] D119636: [NFC][IR] Value: assert this->takeName(this)

Dmitry Vassiliev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 12 09:50:42 PST 2022


slydiman created this revision.
slydiman added reviewers: serge-sans-paille, kazu, aeubanks, nikic, asavonic, krisb.
slydiman added a project: LLVM.
Herald added subscribers: dexonsmith, hiraditya.
slydiman requested review of this revision.
Herald added a subscriber: llvm-commits.

Need to add an assert about this->takeName(this). This restriction is already documented, so this is just an NFC check.
Without this assertion (as prescribed by original comments for this API), name deletion or down-stream assert failures may occur in other routines: e.g. at the beginning of replaceAllUsesWith() below.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119636

Files:
  llvm/lib/IR/Value.cpp


Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -377,6 +377,10 @@
 }
 
 void Value::takeName(Value *V) {
+  // Without this assertion (as prescribed by original comments for this API),
+  // name deletion or down-stream assert failures may occur in other routines:
+  // e.g. at the beginning of replaceAllUsesWith() below.
+  assert(V != this && "Illegal call to this->takeName(this)!");
   ValueSymbolTable *ST = nullptr;
   // If this value has a name, drop it.
   if (hasName()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119636.408190.patch
Type: text/x-patch
Size: 589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220212/7fb04dd0/attachment.bin>


More information about the llvm-commits mailing list