[DAGCombiner] Eliminate dead stores to stack.
[llvm-complete.git] / tools / llvm-c-test / attributes.c
blob826cb094e226f64356ea197b64b2ebdbb476ac7b
1 /*===-- attributes.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 --test-attributes and --test-callsite-attributes *|
11 |* commands in llvm-c-test. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c-test.h"
17 #include <assert.h>
18 #include <stdlib.h>
20 int llvm_test_function_attributes(void) {
21 LLVMEnablePrettyStackTrace();
23 LLVMModuleRef M = llvm_load_module(false, true);
25 LLVMValueRef F = LLVMGetFirstFunction(M);
26 while (F) {
27 // Read attributes
28 int Idx, ParamCount;
29 for (Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F);
30 Idx <= ParamCount; ++Idx) {
31 int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx);
32 LLVMAttributeRef *Attrs =
33 (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef));
34 assert(Attrs);
35 LLVMGetAttributesAtIndex(F, Idx, Attrs);
36 free(Attrs);
38 F = LLVMGetNextFunction(F);
41 LLVMDisposeModule(M);
43 return 0;
46 int llvm_test_callsite_attributes(void) {
47 LLVMEnablePrettyStackTrace();
49 LLVMModuleRef M = llvm_load_module(false, true);
51 LLVMValueRef F = LLVMGetFirstFunction(M);
52 while (F) {
53 LLVMBasicBlockRef BB;
54 for (BB = LLVMGetFirstBasicBlock(F); BB; BB = LLVMGetNextBasicBlock(BB)) {
55 LLVMValueRef I;
56 for (I = LLVMGetFirstInstruction(BB); I; I = LLVMGetNextInstruction(I)) {
57 if (LLVMIsACallInst(I)) {
58 // Read attributes
59 int Idx, ParamCount;
60 for (Idx = LLVMAttributeFunctionIndex,
61 ParamCount = LLVMCountParams(F);
62 Idx <= ParamCount; ++Idx) {
63 int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx);
64 LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc(
65 AttrCount * sizeof(LLVMAttributeRef));
66 assert(Attrs);
67 LLVMGetCallSiteAttributes(I, Idx, Attrs);
68 free(Attrs);
74 F = LLVMGetNextFunction(F);
77 LLVMDisposeModule(M);
79 return 0;