[PATCH] Fix LLVMSetMetadata for MDNodes that contain a single value
Björn Steinbrink
bsteinbr at gmail.com
Sun Jan 25 11:30:34 PST 2015
MetadataAsValue uses a canonical format that strips the MDNode if it
contains only a single constant value. This triggers an assertion when
trying to cast the value to a MDNode.
http://reviews.llvm.org/D7165
Files:
lib/IR/Core.cpp
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp
+++ lib/IR/Core.cpp
@@ -563,9 +563,12 @@
return nullptr;
}
-void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef MD) {
- MDNode *N =
- MD ? cast<MDNode>(unwrap<MetadataAsValue>(MD)->getMetadata()) : nullptr;
+void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
+ Metadata *MD = Val ? unwrap<MetadataAsValue>(Val)->getMetadata() : nullptr;
+
+ MDNode *N = MD
+ ? (isa<MDNode>(MD) ? cast<MDNode>(MD) : MDNode::get(unwrap(Val)->getContext(), MD))
+ : nullptr;
unwrap<Instruction>(Inst)->setMetadata(KindID, N);
}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7165.18731.patch
Type: text/x-patch
Size: 689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150125/5a9f0cb0/attachment.bin>
More information about the llvm-commits
mailing list