[NFC][IR] Value: assert this->takeName(this)
authorDmitry Vassiliev <dvassiliev@accesssoftek.com>
Sun, 13 Feb 2022 18:47:37 +0000 (21:47 +0300)
committerDmitry Vassiliev <dvassiliev@accesssoftek.com>
Sun, 13 Feb 2022 18:47:37 +0000 (21:47 +0300)
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.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D119636

llvm/lib/IR/Value.cpp

index 18aef37..df286df 100644 (file)
@@ -377,6 +377,7 @@ void Value::setName(const Twine &NewName) {
 }
 
 void Value::takeName(Value *V) {
+  assert(V != this && "Illegal call to this->takeName(this)!");
   ValueSymbolTable *ST = nullptr;
   // If this value has a name, drop it.
   if (hasName()) {