Benjamin Kramer | 410780b | 2013-01-12 14:13:45 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/IR/AttributesTest.cpp - Attributes unit tests --------===// |
| 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 | #include "llvm/IR/Attributes.h" |
| 11 | #include "llvm/IR/LLVMContext.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | using namespace llvm; |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | TEST(Attributes, Uniquing) { |
| 18 | LLVMContext C; |
| 19 | |
| 20 | Attribute AttrA = Attribute::get(C, Attribute::AlwaysInline); |
| 21 | Attribute AttrB = Attribute::get(C, Attribute::AlwaysInline); |
| 22 | EXPECT_EQ(AttrA, AttrB); |
| 23 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 24 | AttributeList ASs[] = {AttributeList::get(C, 1, Attribute::ZExt), |
| 25 | AttributeList::get(C, 2, Attribute::SExt)}; |
Benjamin Kramer | 410780b | 2013-01-12 14:13:45 +0000 | [diff] [blame] | 26 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 27 | AttributeList SetA = AttributeList::get(C, ASs); |
| 28 | AttributeList SetB = AttributeList::get(C, ASs); |
Benjamin Kramer | 410780b | 2013-01-12 14:13:45 +0000 | [diff] [blame] | 29 | EXPECT_EQ(SetA, SetB); |
| 30 | } |
| 31 | |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 32 | TEST(Attributes, Ordering) { |
| 33 | LLVMContext C; |
| 34 | |
Reid Kleckner | 7de6761 | 2016-04-04 23:06:05 +0000 | [diff] [blame] | 35 | Attribute Align4 = Attribute::get(C, Attribute::Alignment, 4); |
| 36 | Attribute Align5 = Attribute::get(C, Attribute::Alignment, 5); |
| 37 | Attribute Deref4 = Attribute::get(C, Attribute::Dereferenceable, 4); |
| 38 | Attribute Deref5 = Attribute::get(C, Attribute::Dereferenceable, 5); |
| 39 | EXPECT_TRUE(Align4 < Align5); |
| 40 | EXPECT_TRUE(Align4 < Deref4); |
| 41 | EXPECT_TRUE(Align4 < Deref5); |
| 42 | EXPECT_TRUE(Align5 < Deref4); |
| 43 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 44 | AttributeList ASs[] = {AttributeList::get(C, 2, Attribute::ZExt), |
| 45 | AttributeList::get(C, 1, Attribute::SExt)}; |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 46 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 47 | AttributeList SetA = AttributeList::get(C, ASs); |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame^] | 48 | AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1].getAttributes(1)); |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 49 | EXPECT_NE(SetA, SetB); |
| 50 | } |
| 51 | |
Reid Kleckner | fe64c01 | 2017-04-18 22:10:18 +0000 | [diff] [blame] | 52 | TEST(Attributes, AddAttributes) { |
| 53 | LLVMContext C; |
| 54 | AttributeList AL; |
| 55 | AttrBuilder B; |
| 56 | B.addAttribute(Attribute::NoReturn); |
| 57 | AL = AL.addAttributes(C, AttributeList::FunctionIndex, AttributeSet::get(C, B)); |
| 58 | EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn)); |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 59 | B.clear(); |
| 60 | B.addAttribute(Attribute::SExt); |
| 61 | AL = AL.addAttributes(C, AttributeList::ReturnIndex, B); |
| 62 | EXPECT_TRUE(AL.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt)); |
| 63 | EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn)); |
Reid Kleckner | fe64c01 | 2017-04-18 22:10:18 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Benjamin Kramer | 410780b | 2013-01-12 14:13:45 +0000 | [diff] [blame] | 66 | } // end anonymous namespace |