Skip to content

Commit

Permalink
Cleaner + Another Test
Browse files Browse the repository at this point in the history
  • Loading branch information
goldsteinn committed Oct 2, 2024
1 parent b15106c commit ebc4a92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
18 changes: 5 additions & 13 deletions llvm/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,19 +1802,11 @@ AttributeList::intersectWith(LLVMContext &C, AttributeList Other) const {
return *this;

SmallVector<std::pair<unsigned, AttributeSet>> IntersectedAttrs;
SmallSet<unsigned, 8> AllIndexes{};
AllIndexes.insert(indexes().begin(), indexes().end());
AllIndexes.insert(Other.indexes().begin(), Other.indexes().end());

for (unsigned Idx : AllIndexes) {
AttributeSet ThisSet = {};
AttributeSet OtherSet = {};
if (hasAttributesAtIndex(Idx))
ThisSet = getAttributes(Idx);
if (Other.hasAttributesAtIndex(Idx))
OtherSet = Other.getAttributes(Idx);

auto IntersectedAS = ThisSet.intersectWith(C, OtherSet);
auto IndexIt = index_iterator(std::max(getNumAttrSets(), Other.getNumAttrSets()));
for (unsigned Idx : IndexIt) {
fprintf(stderr, "Checking Idx: %u\n", Idx);
auto IntersectedAS =
getAttributes(Idx).intersectWith(C, Other.getAttributes(Idx));
// If any index fails to intersect, fail.
if (!IntersectedAS)
return std::nullopt;
Expand Down
26 changes: 26 additions & 0 deletions llvm/unittests/IR/AttributesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,32 @@ TEST(Attributes, SetIntersectByValAlign) {
}
}

TEST(Attributes, ListIntersectDifferingMustPreserve) {
LLVMContext C;
fprintf(stderr, "Starting Test!\n");
std::optional<AttributeList> Res;
{
AttributeList AL0;
AttributeList AL1;
AL1 = AL1.addFnAttribute(C, Attribute::ReadOnly);
AL0 = AL0.addParamAttribute(C, 0, Attribute::SExt);
Res = AL0.intersectWith(C, AL1);
ASSERT_FALSE(Res.has_value());
Res = AL1.intersectWith(C, AL0);
ASSERT_FALSE(Res.has_value());
}
{
AttributeList AL0;
AttributeList AL1;
AL1 = AL1.addFnAttribute(C, Attribute::AlwaysInline);
AL0 = AL0.addParamAttribute(C, 0, Attribute::ReadOnly);
Res = AL0.intersectWith(C, AL1);
ASSERT_FALSE(Res.has_value());
Res = AL1.intersectWith(C, AL0);
ASSERT_FALSE(Res.has_value());
}
}

TEST(Attributes, ListIntersect) {
LLVMContext C;
AttributeList AL0;
Expand Down

0 comments on commit ebc4a92

Please sign in to comment.