blob: 9f8013ff181cd61d02c138c2a02a378616547d12 [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
Bill Wendlinga7a55ee2013-01-27 03:39:10 +000024 AttributeSet ASs[] = {
25 AttributeSet::get(C, 1, Attribute::ZExt),
26 AttributeSet::get(C, 2, Attribute::SExt)
Benjamin Kramer410780b2013-01-12 14:13:45 +000027 };
28
Bill Wendlinga7a55ee2013-01-27 03:39:10 +000029 AttributeSet SetA = AttributeSet::get(C, ASs);
30 AttributeSet SetB = AttributeSet::get(C, ASs);
Benjamin Kramer410780b2013-01-12 14:13:45 +000031 EXPECT_EQ(SetA, SetB);
32}
33
Peter Collingbournebd6c7452013-08-02 22:29:40 +000034TEST(Attributes, Ordering) {
35 LLVMContext C;
36
Reid Kleckner7de67612016-04-04 23:06:05 +000037 Attribute Align4 = Attribute::get(C, Attribute::Alignment, 4);
38 Attribute Align5 = Attribute::get(C, Attribute::Alignment, 5);
39 Attribute Deref4 = Attribute::get(C, Attribute::Dereferenceable, 4);
40 Attribute Deref5 = Attribute::get(C, Attribute::Dereferenceable, 5);
41 EXPECT_TRUE(Align4 < Align5);
42 EXPECT_TRUE(Align4 < Deref4);
43 EXPECT_TRUE(Align4 < Deref5);
44 EXPECT_TRUE(Align5 < Deref4);
45
Peter Collingbournebd6c7452013-08-02 22:29:40 +000046 AttributeSet ASs[] = {
47 AttributeSet::get(C, 2, Attribute::ZExt),
48 AttributeSet::get(C, 1, Attribute::SExt)
49 };
50
51 AttributeSet SetA = AttributeSet::get(C, ASs);
52 AttributeSet SetB = SetA.removeAttributes(C, 1, ASs[1]);
53 EXPECT_NE(SetA, SetB);
54}
55
Benjamin Kramer410780b2013-01-12 14:13:45 +000056} // end anonymous namespace