1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 21:13:02 +02:00
llvm-mirror/unittests/IR/AttributesTest.cpp
Reid Kleckner ff47a97341 Re-land r301697 "[IR] Make add/remove Attributes use AttrBuilder instead of AttributeList"
This time, I fixed, built, and tested clang.

This reverts r301712.

llvm-svn: 301981
2017-05-02 22:07:37 +00:00

67 lines
2.2 KiB
C++

//===- llvm/unittest/IR/AttributesTest.cpp - Attributes unit tests --------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/IR/Attributes.h"
#include "llvm/IR/LLVMContext.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
TEST(Attributes, Uniquing) {
LLVMContext C;
Attribute AttrA = Attribute::get(C, Attribute::AlwaysInline);
Attribute AttrB = Attribute::get(C, Attribute::AlwaysInline);
EXPECT_EQ(AttrA, AttrB);
AttributeList ASs[] = {AttributeList::get(C, 1, Attribute::ZExt),
AttributeList::get(C, 2, Attribute::SExt)};
AttributeList SetA = AttributeList::get(C, ASs);
AttributeList SetB = AttributeList::get(C, ASs);
EXPECT_EQ(SetA, SetB);
}
TEST(Attributes, Ordering) {
LLVMContext C;
Attribute Align4 = Attribute::get(C, Attribute::Alignment, 4);
Attribute Align5 = Attribute::get(C, Attribute::Alignment, 5);
Attribute Deref4 = Attribute::get(C, Attribute::Dereferenceable, 4);
Attribute Deref5 = Attribute::get(C, Attribute::Dereferenceable, 5);
EXPECT_TRUE(Align4 < Align5);
EXPECT_TRUE(Align4 < Deref4);
EXPECT_TRUE(Align4 < Deref5);
EXPECT_TRUE(Align5 < Deref4);
AttributeList ASs[] = {AttributeList::get(C, 2, Attribute::ZExt),
AttributeList::get(C, 1, Attribute::SExt)};
AttributeList SetA = AttributeList::get(C, ASs);
AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1].getAttributes(1));
EXPECT_NE(SetA, SetB);
}
TEST(Attributes, AddAttributes) {
LLVMContext C;
AttributeList AL;
AttrBuilder B;
B.addAttribute(Attribute::NoReturn);
AL = AL.addAttributes(C, AttributeList::FunctionIndex, AttributeSet::get(C, B));
EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn));
B.clear();
B.addAttribute(Attribute::SExt);
AL = AL.addAttributes(C, AttributeList::ReturnIndex, B);
EXPECT_TRUE(AL.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt));
EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn));
}
} // end anonymous namespace