blob: 0df7a847f8a5636dca01436e0b47e95cf2720cf6 [file] [log] [blame]
Benjamin Kramer410780b2013-01-12 14:13:45 +00001//===- 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"
13using namespace llvm;
14
15namespace {
16
17TEST(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 Klecknerb5180542017-03-21 16:57:19 +000024 AttributeList ASs[] = {AttributeList::get(C, 1, Attribute::ZExt),
25 AttributeList::get(C, 2, Attribute::SExt)};
Benjamin Kramer410780b2013-01-12 14:13:45 +000026
Reid Klecknerb5180542017-03-21 16:57:19 +000027 AttributeList SetA = AttributeList::get(C, ASs);
28 AttributeList SetB = AttributeList::get(C, ASs);
Benjamin Kramer410780b2013-01-12 14:13:45 +000029 EXPECT_EQ(SetA, SetB);
30}
31
Peter Collingbournebd6c7452013-08-02 22:29:40 +000032TEST(Attributes, Ordering) {
33 LLVMContext C;
34
Reid Kleckner7de67612016-04-04 23:06:05 +000035 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 Klecknerb5180542017-03-21 16:57:19 +000044 AttributeList ASs[] = {AttributeList::get(C, 2, Attribute::ZExt),
45 AttributeList::get(C, 1, Attribute::SExt)};
Peter Collingbournebd6c7452013-08-02 22:29:40 +000046
Reid Klecknerb5180542017-03-21 16:57:19 +000047 AttributeList SetA = AttributeList::get(C, ASs);
Reid Kleckneree4930b2017-05-02 22:07:37 +000048 AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1].getAttributes(1));
Peter Collingbournebd6c7452013-08-02 22:29:40 +000049 EXPECT_NE(SetA, SetB);
50}
51
Reid Klecknerfe64c012017-04-18 22:10:18 +000052TEST(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 Kleckner61906252017-04-19 01:51:13 +000059 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 Klecknerfe64c012017-04-18 22:10:18 +000064}
65
Benjamin Kramer410780b2013-01-12 14:13:45 +000066} // end anonymous namespace