From d56bbdff81bb749eda17462270a54ee85c69177b Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 13 Oct 2018 00:56:46 -0400 Subject: [PATCH] Add global erasure --- Sources/LLVM/IRGlobal.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/LLVM/IRGlobal.swift b/Sources/LLVM/IRGlobal.swift index 6f7677f6..92da5b1d 100644 --- a/Sources/LLVM/IRGlobal.swift +++ b/Sources/LLVM/IRGlobal.swift @@ -57,4 +57,17 @@ extension IRGlobal { } set { LLVMSetSection(asLLVM(), newValue) } } + + /// Removes this global value from the module and deallocates it. + /// + /// - note: To ensure correct removal of the global value, you must invalidate + /// any references to it - usually by performing an + /// "Replace All Uses With" (RAUW) operation. + /// + /// - warning: The native Swift object wrapping this global becomes a dangling + /// reference once this function has been invoked. It is + /// recommended that all references to it be dropped immediately. + public func eraseFromParent() { + LLVMDeleteGlobal(self.asLLVM()) + } }