llvm.org GIT mirror llvm / 698be08
IR: Remove an invalid assertion when replacing resolved operands This adds back the testcase from r225738, and adds to it. Looks like we need both sides for now (the assertion was incorrect both ways, and although it seemed reasonable (when written correctly) it wasn't particularly important). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225745 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
2 changed file(s) with 32 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
442442 assert(SubclassData32 != 0 && "Expected unresolved operands");
443443
444444 // Check if an operand was resolved.
445 if (!isOperandUnresolved(Old))
446 assert(isOperandUnresolved(New) && "Operand just became unresolved");
447 else if (!isOperandUnresolved(New))
445 if (!isOperandUnresolved(Old)) {
446 if (isOperandUnresolved(New))
447 // An operand was un-resolved!
448 ++SubclassData32;
449 } else if (!isOperandUnresolved(New))
448450 decrementUnresolvedOperandCount();
449451 }
450452
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "llvm/ADT/STLExtras.h"
910 #include "llvm/IR/Metadata.h"
1011 #include "llvm/IR/Constants.h"
1112 #include "llvm/IR/Instructions.h"
360361 EXPECT_EQ(N4, N6->getOperand(0));
361362 }
362363
364 TEST_F(MDNodeTest, replaceResolvedOperand) {
365 // Check code for replacing one resolved operand with another. If doing this
366 // directly (via replaceOperandWith()) becomes illegal, change the operand to
367 // a global value that gets RAUW'ed.
368 //
369 // Use a temporary node to keep N from being resolved.
370 std::unique_ptr Temp(MDNodeFwdDecl::get(Context, None));
371 Metadata *Ops[] = {nullptr, Temp.get()};
372
373 MDNode *Empty = MDTuple::get(Context, {});
374 MDNode *N = MDTuple::get(Context, Ops);
375 EXPECT_EQ(nullptr, N->getOperand(0));
376 ASSERT_FALSE(N->isResolved());
377
378 // Check code for replacing resolved nodes.
379 N->replaceOperandWith(0, Empty);
380 EXPECT_EQ(Empty, N->getOperand(0));
381
382 // Check code for adding another unresolved operand.
383 N->replaceOperandWith(0, Temp.get());
384 EXPECT_EQ(Temp.get(), N->getOperand(0));
385
386 // Remove the references to Temp; required for teardown.
387 Temp->replaceAllUsesWith(nullptr);
388 }
389
363390 typedef MetadataTest MetadataAsValueTest;
364391
365392 TEST_F(MetadataAsValueTest, MDNode) {