blob: c6beab1d31b006230814ed1c815eb054713330a2 [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
Richard Smith6b335d12016-11-16 03:36:29 +000027 int Idx, ParamCount;
28 for (Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F);
Amaury Sechet003216b2016-11-15 22:19:59 +000029 Idx <= ParamCount; ++Idx) {
30 int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx);
31 LLVMAttributeRef *Attrs =
32 (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef));
33 LLVMGetAttributesAtIndex(F, Idx, Attrs);
34 free(Attrs);
35 }
36 F = LLVMGetNextFunction(F);
37 }
38
39 LLVMDisposeModule(M);
40
41 return 0;
42}
43
44int llvm_test_callsite_attributes(void) {
45 LLVMEnablePrettyStackTrace();
46
47 LLVMModuleRef M = llvm_load_module(false, true);
48
49 LLVMValueRef F = LLVMGetFirstFunction(M);
50 while (F) {
51 LLVMBasicBlockRef BB;
52 for (BB = LLVMGetFirstBasicBlock(F); BB; BB = LLVMGetNextBasicBlock(BB)) {
53 LLVMValueRef I;
54 for (I = LLVMGetFirstInstruction(BB); I; I = LLVMGetNextInstruction(I)) {
55 if (LLVMIsACallInst(I)) {
56 // Read attributes
Richard Smith6b335d12016-11-16 03:36:29 +000057 int Idx, ParamCount;
58 for (Idx = LLVMAttributeFunctionIndex,
59 ParamCount = LLVMCountParams(F);
Amaury Sechet003216b2016-11-15 22:19:59 +000060 Idx <= ParamCount; ++Idx) {
61 int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx);
62 LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc(
63 AttrCount * sizeof(LLVMAttributeRef));
64 LLVMGetCallSiteAttributes(I, Idx, Attrs);
65 free(Attrs);
66 }
67 }
68 }
69 }
70
71 F = LLVMGetNextFunction(F);
72 }
73
74 LLVMDisposeModule(M);
75
76 return 0;
77}