1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00
llvm-mirror/unittests/IR/AttributesTest.cpp
Reid Kleckner 73b2ef28fd Fix non-determinism in order of LLVM attributes
We were using array_pod_sort on an array of type 'Attribute', which
wraps a pointer to AttributeImpl. For the most part this didn't matter
because the printing code prints enum attributes in a defined order, but
integer attributes such as 'align' and 'dereferenceable' were not
ordered.

Furthermore, AttributeImpl::operator< was broken for integer attributes.
An integer attribute is a kind and an integer value, and both pieces
need to be compared.

By fixing the comparison operator, we can go back to std::sort, and
things look good now.  This should fix clang arm-swiftcall.c test
failures on Windows.

llvm-svn: 265361
2016-04-04 23:06:05 +00:00

57 lines
1.6 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);
AttributeSet ASs[] = {
AttributeSet::get(C, 1, Attribute::ZExt),
AttributeSet::get(C, 2, Attribute::SExt)
};
AttributeSet SetA = AttributeSet::get(C, ASs);
AttributeSet SetB = AttributeSet::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);
AttributeSet ASs[] = {
AttributeSet::get(C, 2, Attribute::ZExt),
AttributeSet::get(C, 1, Attribute::SExt)
};
AttributeSet SetA = AttributeSet::get(C, ASs);
AttributeSet SetB = SetA.removeAttributes(C, 1, ASs[1]);
EXPECT_NE(SetA, SetB);
}
} // end anonymous namespace