[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / tools / llvm-c-test / metadata.c
blobb1d76083cd727e898ade1054bd4f770a83a49322
1 /*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This file implements the --add-named-metadata-operand and --set-metadata *|
11 |* commands in llvm-c-test. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c-test.h"
17 int llvm_add_named_metadata_operand(void) {
18 LLVMModuleRef m = LLVMModuleCreateWithName("Mod");
19 LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
21 // This used to trigger an assertion
22 LLVMAddNamedMetadataOperand(m, "name", LLVMMDNode(values, 1));
24 LLVMDisposeModule(m);
26 return 0;
29 int llvm_set_metadata(void) {
30 LLVMBuilderRef b = LLVMCreateBuilder();
31 LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
33 // This used to trigger an assertion
34 LLVMValueRef ret = LLVMBuildRetVoid(b);
35 LLVMSetMetadata(ret, LLVMGetMDKindID("kind", 4), LLVMMDNode(values, 1));
37 LLVMDisposeBuilder(b);
38 LLVMDeleteInstruction(ret);
40 return 0;