llvm.org GIT mirror llvm / 9e4a11f
IR: Fix a use-after-free in RAUW Happened pretty commonly during `LLVMContext` teardown when `clang -g` hit an error. This fixes the use-after-free. Next I'll clean up teardown so that it's not RAUW'ing when metadata-tracked values are deleted (only really causes a problem if the graph is mid-construction when teardown starts, but it's still unnecessary work). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226029 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
2 changed file(s) with 33 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
166166 return L.second.second < R.second.second;
167167 });
168168 for (const auto &Pair : Uses) {
169 // Check that this Ref hasn't disappeared after RAUW (when updating a
170 // previous Ref).
171 if (!UseMap.count(Pair.first))
172 continue;
173
169174 OwnerTy Owner = Pair.second.first;
170175 if (!Owner) {
171176 // Update unowned tracking references directly.
483483 EXPECT_TRUE(MD->getValue() == GV1.get());
484484 }
485485
486 TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) {
487 // Create a constant.
488 ConstantAsMetadata *CI = ConstantAsMetadata::get(
489 ConstantInt::get(getGlobalContext(), APInt(8, 0)));
490
491 // Create a temporary to prevent nodes from resolving.
492 std::unique_ptr Temp(MDNode::getTemporary(Context, None));
493
494 // When the first operand of N1 gets reset to nullptr, it'll collide with N2.
495 Metadata *Ops1[] = {CI, CI, Temp.get()};
496 Metadata *Ops2[] = {nullptr, CI, Temp.get()};
497
498 auto *N1 = MDTuple::get(Context, Ops1);
499 auto *N2 = MDTuple::get(Context, Ops2);
500 ASSERT_NE(N1, N2);
501
502 // Tell metadata that the constant is getting deleted.
503 //
504 // After this, N1 will be invalid, so don't touch it.
505 ValueAsMetadata::handleDeletion(CI->getValue());
506 EXPECT_EQ(nullptr, N2->getOperand(0));
507 EXPECT_EQ(nullptr, N2->getOperand(1));
508 EXPECT_EQ(Temp.get(), N2->getOperand(2));
509
510 // Clean up Temp for teardown.
511 Temp->replaceAllUsesWith(nullptr);
512 }
513
486514 typedef MetadataTest TrackingMDRefTest;
487515
488516 TEST_F(TrackingMDRefTest, UpdatesOnRAUW) {