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 \*===----------------------------------------------------------------------===*/
14 
15 #include "llvm-c-test.h"
16 
llvm_add_named_metadata_operand(void)17 int llvm_add_named_metadata_operand(void) {
18   LLVMModuleRef m = LLVMModuleCreateWithName("Mod");
19   LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
20 
21   // This used to trigger an assertion
22   LLVMAddNamedMetadataOperand(m, "name", LLVMMDNode(values, 1));
23 
24   LLVMDisposeModule(m);
25 
26   return 0;
27 }
28 
llvm_set_metadata(void)29 int llvm_set_metadata(void) {
30   LLVMBuilderRef b = LLVMCreateBuilder();
31   LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
32 
33   // This used to trigger an assertion
34   LLVMSetMetadata(
35       LLVMBuildRetVoid(b),
36       LLVMGetMDKindID("kind", 4),
37       LLVMMDNode(values, 1));
38 
39   LLVMDisposeBuilder(b);
40 
41   return 0;
42 }
43