blob: 7f07a220ad3562e0ece164f08052548f2d1cf9e0 [file] [log] [blame]
Amaury Sechet003216b2016-11-15 22:19:59 +00001/*===-- attributes.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 --test-attributes and --test-callsite-attributes *|
11|* commands in llvm-c-test. *|
12|* *|
13\*===----------------------------------------------------------------------===*/
14
15#include "llvm-c-test.h"
16
17#include <stdlib.h>
18
19int llvm_test_function_attributes(void) {
20 LLVMEnablePrettyStackTrace();
21
22 LLVMModuleRef M = llvm_load_module(false, true);
23
24 LLVMValueRef F = LLVMGetFirstFunction(M);
25 while (F) {
26 // Read attributes
27 for (int Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F);
28 Idx <= ParamCount; ++Idx) {
29 int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx);
30 LLVMAttributeRef *Attrs =
31 (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef));
32 LLVMGetAttributesAtIndex(F, Idx, Attrs);
33 free(Attrs);
34 }
35 F = LLVMGetNextFunction(F);
36 }
37
38 LLVMDisposeModule(M);
39
40 return 0;
41}
42
43int llvm_test_callsite_attributes(void) {
44 LLVMEnablePrettyStackTrace();
45
46 LLVMModuleRef M = llvm_load_module(false, true);
47
48 LLVMValueRef F = LLVMGetFirstFunction(M);
49 while (F) {
50 LLVMBasicBlockRef BB;
51 for (BB = LLVMGetFirstBasicBlock(F); BB; BB = LLVMGetNextBasicBlock(BB)) {
52 LLVMValueRef I;
53 for (I = LLVMGetFirstInstruction(BB); I; I = LLVMGetNextInstruction(I)) {
54 if (LLVMIsACallInst(I)) {
55 // Read attributes
56 for (int Idx = LLVMAttributeFunctionIndex,
57 ParamCount = LLVMCountParams(F);
58 Idx <= ParamCount; ++Idx) {
59 int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx);
60 LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc(
61 AttrCount * sizeof(LLVMAttributeRef));
62 LLVMGetCallSiteAttributes(I, Idx, Attrs);
63 free(Attrs);
64 }
65 }
66 }
67 }
68
69 F = LLVMGetNextFunction(F);
70 }
71
72 LLVMDisposeModule(M);
73
74 return 0;
75}