Skip to content

Commit ebc4a92

Browse files
committed
Cleaner + Another Test
1 parent b15106c commit ebc4a92

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

llvm/lib/IR/Attributes.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,19 +1802,11 @@ AttributeList::intersectWith(LLVMContext &C, AttributeList Other) const {
18021802
return *this;
18031803

18041804
SmallVector<std::pair<unsigned, AttributeSet>> IntersectedAttrs;
1805-
SmallSet<unsigned, 8> AllIndexes{};
1806-
AllIndexes.insert(indexes().begin(), indexes().end());
1807-
AllIndexes.insert(Other.indexes().begin(), Other.indexes().end());
1808-
1809-
for (unsigned Idx : AllIndexes) {
1810-
AttributeSet ThisSet = {};
1811-
AttributeSet OtherSet = {};
1812-
if (hasAttributesAtIndex(Idx))
1813-
ThisSet = getAttributes(Idx);
1814-
if (Other.hasAttributesAtIndex(Idx))
1815-
OtherSet = Other.getAttributes(Idx);
1816-
1817-
auto IntersectedAS = ThisSet.intersectWith(C, OtherSet);
1805+
auto IndexIt = index_iterator(std::max(getNumAttrSets(), Other.getNumAttrSets()));
1806+
for (unsigned Idx : IndexIt) {
1807+
fprintf(stderr, "Checking Idx: %u\n", Idx);
1808+
auto IntersectedAS =
1809+
getAttributes(Idx).intersectWith(C, Other.getAttributes(Idx));
18181810
// If any index fails to intersect, fail.
18191811
if (!IntersectedAS)
18201812
return std::nullopt;

llvm/unittests/IR/AttributesTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,32 @@ TEST(Attributes, SetIntersectByValAlign) {
596596
}
597597
}
598598

599+
TEST(Attributes, ListIntersectDifferingMustPreserve) {
600+
LLVMContext C;
601+
fprintf(stderr, "Starting Test!\n");
602+
std::optional<AttributeList> Res;
603+
{
604+
AttributeList AL0;
605+
AttributeList AL1;
606+
AL1 = AL1.addFnAttribute(C, Attribute::ReadOnly);
607+
AL0 = AL0.addParamAttribute(C, 0, Attribute::SExt);
608+
Res = AL0.intersectWith(C, AL1);
609+
ASSERT_FALSE(Res.has_value());
610+
Res = AL1.intersectWith(C, AL0);
611+
ASSERT_FALSE(Res.has_value());
612+
}
613+
{
614+
AttributeList AL0;
615+
AttributeList AL1;
616+
AL1 = AL1.addFnAttribute(C, Attribute::AlwaysInline);
617+
AL0 = AL0.addParamAttribute(C, 0, Attribute::ReadOnly);
618+
Res = AL0.intersectWith(C, AL1);
619+
ASSERT_FALSE(Res.has_value());
620+
Res = AL1.intersectWith(C, AL0);
621+
ASSERT_FALSE(Res.has_value());
622+
}
623+
}
624+
599625
TEST(Attributes, ListIntersect) {
600626
LLVMContext C;
601627
AttributeList AL0;

0 commit comments

Comments
 (0)