aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-04-04 23:06:05 +0000
committerReid Kleckner <rnk@google.com>2016-04-04 23:06:05 +0000
commit7de6761561012aa726c6fd495ab55bc1a67d5e9a (patch)
treed334d6f36362fe114da06d39fe9792e655d6fb18 /llvm/lib/IR/Attributes.cpp
parente77c7de45956194d4f68296e92d88d6e99f783ba (diff)
downloadllvm-7de6761561012aa726c6fd495ab55bc1a67d5e9a.zip
llvm-7de6761561012aa726c6fd495ab55bc1a67d5e9a.tar.gz
llvm-7de6761561012aa726c6fd495ab55bc1a67d5e9a.tar.bz2
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
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r--llvm/lib/IR/Attributes.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index b8c03de..19664f7 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -389,7 +389,11 @@ bool AttributeImpl::operator<(const AttributeImpl &AI) const {
if (isIntAttribute()) {
if (AI.isEnumAttribute()) return false;
- if (AI.isIntAttribute()) return getValueAsInt() < AI.getValueAsInt();
+ if (AI.isIntAttribute()) {
+ if (getKindAsEnum() == AI.getKindAsEnum())
+ return getValueAsInt() < AI.getValueAsInt();
+ return getKindAsEnum() < AI.getKindAsEnum();
+ }
if (AI.isStringAttribute()) return true;
}
@@ -482,7 +486,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
FoldingSetNodeID ID;
SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
- array_pod_sort(SortedAttrs.begin(), SortedAttrs.end());
+ std::sort(SortedAttrs.begin(), SortedAttrs.end());
for (Attribute Attr : SortedAttrs)
Attr.Profile(ID);