1 /*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
2 |* *|
3 |* The LLVM Compiler Infrastructure *|
4 |* *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This file implements the --add-named-metadata-operand and --set-metadata *|
11 |* commands in llvm-c-test. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
14
15 #include "llvm-c-test.h"
16 #include "llvm-c/Core.h"
17
add_named_metadata_operand(void)18 int add_named_metadata_operand(void) {
19 LLVMModuleRef m = LLVMModuleCreateWithName("Mod");
20 LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
21
22 // This used to trigger an assertion
23 LLVMAddNamedMetadataOperand(m, "name", LLVMMDNode(values, 1));
24
25 LLVMDisposeModule(m);
26
27 return 0;
28 }
29
set_metadata(void)30 int set_metadata(void) {
31 LLVMBuilderRef b = LLVMCreateBuilder();
32 LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
33
34 // This used to trigger an assertion
35 LLVMSetMetadata(
36 LLVMBuildRetVoid(b),
37 LLVMGetMDKindID("kind", 4),
38 LLVMMDNode(values, 1));
39
40 LLVMDisposeBuilder(b);
41
42 return 0;
43 }
44