Amaury Sechet | b451ba8 | 2016-11-15 22:19:59 +0000 | [diff] [blame] | 1 | /*===-- 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 | |
Serge Pavlov | 06c71d8 | 2018-02-20 05:41:26 +0000 | [diff] [blame] | 17 | #include <assert.h> |
Amaury Sechet | b451ba8 | 2016-11-15 22:19:59 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | |
| 20 | int llvm_test_function_attributes(void) { |
| 21 | LLVMEnablePrettyStackTrace(); |
| 22 | |
| 23 | LLVMModuleRef M = llvm_load_module(false, true); |
| 24 | |
| 25 | LLVMValueRef F = LLVMGetFirstFunction(M); |
| 26 | while (F) { |
| 27 | // Read attributes |
Richard Smith | 79e3fcd | 2016-11-16 03:36:29 +0000 | [diff] [blame] | 28 | int Idx, ParamCount; |
| 29 | for (Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F); |
Amaury Sechet | b451ba8 | 2016-11-15 22:19:59 +0000 | [diff] [blame] | 30 | Idx <= ParamCount; ++Idx) { |
| 31 | int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx); |
| 32 | LLVMAttributeRef *Attrs = |
| 33 | (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef)); |
Serge Pavlov | 06c71d8 | 2018-02-20 05:41:26 +0000 | [diff] [blame] | 34 | assert(Attrs); |
Amaury Sechet | b451ba8 | 2016-11-15 22:19:59 +0000 | [diff] [blame] | 35 | LLVMGetAttributesAtIndex(F, Idx, Attrs); |
| 36 | free(Attrs); |
| 37 | } |
| 38 | F = LLVMGetNextFunction(F); |
| 39 | } |
| 40 | |
| 41 | LLVMDisposeModule(M); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int llvm_test_callsite_attributes(void) { |
| 47 | LLVMEnablePrettyStackTrace(); |
| 48 | |
| 49 | LLVMModuleRef M = llvm_load_module(false, true); |
| 50 | |
| 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 |
Richard Smith | 79e3fcd | 2016-11-16 03:36:29 +0000 | [diff] [blame] | 59 | int Idx, ParamCount; |
| 60 | for (Idx = LLVMAttributeFunctionIndex, |
| 61 | ParamCount = LLVMCountParams(F); |
Amaury Sechet | b451ba8 | 2016-11-15 22:19:59 +0000 | [diff] [blame] | 62 | Idx <= ParamCount; ++Idx) { |
| 63 | int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx); |
| 64 | LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc( |
| 65 | AttrCount * sizeof(LLVMAttributeRef)); |
Serge Pavlov | 06c71d8 | 2018-02-20 05:41:26 +0000 | [diff] [blame] | 66 | assert(Attrs); |
Amaury Sechet | b451ba8 | 2016-11-15 22:19:59 +0000 | [diff] [blame] | 67 | LLVMGetCallSiteAttributes(I, Idx, Attrs); |
| 68 | free(Attrs); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | F = LLVMGetNextFunction(F); |
| 75 | } |
| 76 | |
| 77 | LLVMDisposeModule(M); |
| 78 | |
| 79 | return 0; |
| 80 | } |