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.
Details
Details
- Reviewers
dexonsmith - Commits
- rGac43b5217915: Merging r227319: --------------------------------------------------------------…
rGa09ac0085d33: Fix LLVMSetMetadata and LLVMAddNamedMetadataOperand for single value MDNodes
rL227319: Fix LLVMSetMetadata and LLVMAddNamedMetadataOperand for single value MDNodes
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
AFK, sorry for the terseness.
Looks correct; thanks for working on this.
- Testcase?
- All the ternary operators are hard to read. I'd switch to ifs and early returns.
- Unwrapping Val twice is a little confusing (and, unnecessary).
- dpnes
Comment Actions
Thanks for the feedback!
Added a testcase and replaced the ternary operators with if statements.
I did not use an early return for the !Val case though, because that would,
AFAICT, stop the user from removing existing metadata.
Comment Actions
Added an MDNode extraction function with proper assertions, fixed
LLVMAddNamedMetadataOperand, and wrote a test for it.
Comment Actions
Updated the header in metadata.c to mention the second command implemented in that file. Sorry for the noise.