[PATCH] D129114: llvm-c: Add LLVMDeleteInstruction to fix a test issue
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 02:13:51 PDT 2022
nhaehnle created this revision.
nhaehnle added reviewers: efriedma, lattner.
Herald added a reviewer: deadalnix.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added a project: LLVM.
Not deleting the loose instruction with metadata associated to it causes
an assertion when the LLVMContext is destroyed. This was previously
hidden by the fact that llvm-c-test does not call LLVMShutdown. The
planned removal of ManagedStatic exposed this issue.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129114
Files:
llvm/docs/ReleaseNotes.rst
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
llvm/tools/llvm-c-test/metadata.c
Index: llvm/tools/llvm-c-test/metadata.c
===================================================================
--- llvm/tools/llvm-c-test/metadata.c
+++ llvm/tools/llvm-c-test/metadata.c
@@ -31,12 +31,11 @@
LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
// This used to trigger an assertion
- LLVMSetMetadata(
- LLVMBuildRetVoid(b),
- LLVMGetMDKindID("kind", 4),
- LLVMMDNode(values, 1));
+ LLVMValueRef ret = LLVMBuildRetVoid(b);
+ LLVMSetMetadata(ret, LLVMGetMDKindID("kind", 4), LLVMMDNode(values, 1));
LLVMDisposeBuilder(b);
+ LLVMDeleteInstruction(ret);
return 0;
}
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -2843,6 +2843,10 @@
unwrap<Instruction>(Inst)->eraseFromParent();
}
+void LLVMDeleteInstruction(LLVMValueRef Inst) {
+ unwrap<Instruction>(Inst)->deleteValue();
+}
+
LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
return (LLVMIntPredicate)I->getPredicate();
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -3231,7 +3231,7 @@
LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
/**
- * Remove and delete an instruction.
+ * Remove an instruction.
*
* The instruction specified is removed from its containing building
* block but is kept alive.
@@ -3250,6 +3250,16 @@
*/
void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
+/**
+ * Delete an instruction.
+ *
+ * The instruction specified is deleted. It must have previously been
+ * removed from its containing building block.
+ *
+ * @see llvm::Value::deleteValue()
+ */
+void LLVMDeleteInstruction(LLVMValueRef Inst);
+
/**
* Obtain the code opcode for an individual instruction.
*
Index: llvm/docs/ReleaseNotes.rst
===================================================================
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -180,6 +180,9 @@
constant fold the operands if possible and create an instruction otherwise:
* ``LLVMConstExtractValue``
+* Add ``LLVMDeleteInstruction`` function which allows deleting instructions that
+ are not inserted into a basic block.
+
Changes to the Go bindings
--------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129114.442213.patch
Type: text/x-patch
Size: 2415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/755dc8d0/attachment.bin>
More information about the llvm-commits
mailing list