Mercurial > hg > CbC > CbC_llvm
comparison unittests/IR/FunctionTest.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- FunctionTest.cpp - Function unit tests -----------------------------===// | 1 //===- FunctionTest.cpp - Function unit tests -----------------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 | 8 |
10 #include "llvm/IR/Function.h" | 9 #include "llvm/IR/Function.h" |
11 #include "llvm/IR/Module.h" | 10 #include "llvm/IR/Module.h" |
31 EXPECT_EQ(2u, F->arg_size()); | 30 EXPECT_EQ(2u, F->arg_size()); |
32 EXPECT_TRUE(F->hasLazyArguments()); | 31 EXPECT_TRUE(F->hasLazyArguments()); |
33 | 32 |
34 // The argument list should be populated at first access. | 33 // The argument list should be populated at first access. |
35 (void)F->arg_begin(); | 34 (void)F->arg_begin(); |
35 EXPECT_FALSE(F->hasLazyArguments()); | |
36 | |
37 // Checking that getArg gets the arguments from F1 in the correct order. | |
38 unsigned i = 0; | |
39 for (Argument &A : F->args()) { | |
40 EXPECT_EQ(&A, F->getArg(i)); | |
41 ++i; | |
42 } | |
36 EXPECT_FALSE(F->hasLazyArguments()); | 43 EXPECT_FALSE(F->hasLazyArguments()); |
37 } | 44 } |
38 | 45 |
39 TEST(FunctionTest, stealArgumentListFrom) { | 46 TEST(FunctionTest, stealArgumentListFrom) { |
40 LLVMContext C; | 47 LLVMContext C; |
128 F->setSection(".text.test2"); | 135 F->setSection(".text.test2"); |
129 EXPECT_TRUE(F->getSection() == ".text.test2"); | 136 EXPECT_TRUE(F->getSection() == ".text.test2"); |
130 EXPECT_TRUE(F->hasSection()); | 137 EXPECT_TRUE(F->hasSection()); |
131 } | 138 } |
132 | 139 |
140 TEST(FunctionTest, GetPointerAlignment) { | |
141 LLVMContext Context; | |
142 Type *VoidType(Type::getVoidTy(Context)); | |
143 FunctionType *FuncType(FunctionType::get(VoidType, false)); | |
144 std::unique_ptr<Function> Func(Function::Create( | |
145 FuncType, GlobalValue::ExternalLinkage)); | |
146 EXPECT_EQ(0U, Func->getPointerAlignment(DataLayout(""))); | |
147 EXPECT_EQ(1U, Func->getPointerAlignment(DataLayout("Fi8"))); | |
148 EXPECT_EQ(1U, Func->getPointerAlignment(DataLayout("Fn8"))); | |
149 EXPECT_EQ(2U, Func->getPointerAlignment(DataLayout("Fi16"))); | |
150 EXPECT_EQ(2U, Func->getPointerAlignment(DataLayout("Fn16"))); | |
151 EXPECT_EQ(4U, Func->getPointerAlignment(DataLayout("Fi32"))); | |
152 EXPECT_EQ(4U, Func->getPointerAlignment(DataLayout("Fn32"))); | |
153 | |
154 Func->setAlignment(4U); | |
155 | |
156 EXPECT_EQ(0U, Func->getPointerAlignment(DataLayout(""))); | |
157 EXPECT_EQ(1U, Func->getPointerAlignment(DataLayout("Fi8"))); | |
158 EXPECT_EQ(4U, Func->getPointerAlignment(DataLayout("Fn8"))); | |
159 EXPECT_EQ(2U, Func->getPointerAlignment(DataLayout("Fi16"))); | |
160 EXPECT_EQ(4U, Func->getPointerAlignment(DataLayout("Fn16"))); | |
161 EXPECT_EQ(4U, Func->getPointerAlignment(DataLayout("Fi32"))); | |
162 EXPECT_EQ(4U, Func->getPointerAlignment(DataLayout("Fn32"))); | |
163 } | |
164 | |
133 } // end namespace | 165 } // end namespace |