1 /*===-- attributes.c - tool for testing libLLVM and llvm-c API ------------===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
8 |*===----------------------------------------------------------------------===*|
10 |* This file implements the --test-attributes and --test-callsite-attributes *|
11 |* commands in llvm-c-test. *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c-test.h"
20 int llvm_test_function_attributes(void) {
21 LLVMEnablePrettyStackTrace();
23 LLVMModuleRef M
= llvm_load_module(false, true);
25 LLVMValueRef F
= LLVMGetFirstFunction(M
);
29 for (Idx
= LLVMAttributeFunctionIndex
, ParamCount
= LLVMCountParams(F
);
30 Idx
<= ParamCount
; ++Idx
) {
31 int AttrCount
= LLVMGetAttributeCountAtIndex(F
, Idx
);
32 LLVMAttributeRef
*Attrs
= 0;
35 (LLVMAttributeRef
*)malloc(AttrCount
* sizeof(LLVMAttributeRef
));
38 LLVMGetAttributesAtIndex(F
, Idx
, Attrs
);
41 F
= LLVMGetNextFunction(F
);
49 int llvm_test_callsite_attributes(void) {
50 LLVMEnablePrettyStackTrace();
52 LLVMModuleRef M
= llvm_load_module(false, true);
54 LLVMValueRef F
= LLVMGetFirstFunction(M
);
57 for (BB
= LLVMGetFirstBasicBlock(F
); BB
; BB
= LLVMGetNextBasicBlock(BB
)) {
59 for (I
= LLVMGetFirstInstruction(BB
); I
; I
= LLVMGetNextInstruction(I
)) {
60 if (LLVMIsACallInst(I
)) {
63 for (Idx
= LLVMAttributeFunctionIndex
,
64 ParamCount
= LLVMCountParams(F
);
65 Idx
<= ParamCount
; ++Idx
) {
66 int AttrCount
= LLVMGetCallSiteAttributeCount(I
, Idx
);
67 LLVMAttributeRef
*Attrs
= 0;
69 Attrs
= (LLVMAttributeRef
*)malloc(
70 AttrCount
* sizeof(LLVMAttributeRef
));
73 LLVMGetCallSiteAttributes(I
, Idx
, Attrs
);
80 F
= LLVMGetNextFunction(F
);