@@ -596,6 +596,38 @@ TEST(Attributes, SetIntersectByValAlign) {
596596 }
597597}
598598
599+ TEST (Attributes, ListIntersectDifferingMustPreserve) {
600+ LLVMContext C;
601+ std::optional<AttributeList> Res;
602+ {
603+ AttributeList AL0;
604+ AttributeList AL1;
605+ AL1 = AL1.addFnAttribute (C, Attribute::ReadOnly);
606+ AL0 = AL0.addParamAttribute (C, 0 , Attribute::SExt);
607+ Res = AL0.intersectWith (C, AL1);
608+ ASSERT_FALSE (Res.has_value ());
609+ Res = AL1.intersectWith (C, AL0);
610+ ASSERT_FALSE (Res.has_value ());
611+ }
612+ {
613+ AttributeList AL0;
614+ AttributeList AL1;
615+ AL1 = AL1.addFnAttribute (C, Attribute::AlwaysInline);
616+ AL0 = AL0.addParamAttribute (C, 0 , Attribute::ReadOnly);
617+ Res = AL0.intersectWith (C, AL1);
618+ ASSERT_FALSE (Res.has_value ());
619+ Res = AL1.intersectWith (C, AL0);
620+ ASSERT_FALSE (Res.has_value ());
621+
622+ AL0 = AL0.addFnAttribute (C, Attribute::AlwaysInline);
623+ AL1 = AL1.addParamAttribute (C, 1 , Attribute::SExt);
624+ Res = AL0.intersectWith (C, AL1);
625+ ASSERT_FALSE (Res.has_value ());
626+ Res = AL1.intersectWith (C, AL0);
627+ ASSERT_FALSE (Res.has_value ());
628+ }
629+ }
630+
599631TEST (Attributes, ListIntersect) {
600632 LLVMContext C;
601633 AttributeList AL0;
@@ -610,11 +642,16 @@ TEST(Attributes, ListIntersect) {
610642
611643 AL0 = AL0.addParamAttribute (C, 1 , Attribute::NoUndef);
612644 Res = AL0.intersectWith (C, AL1);
613- ASSERT_FALSE (Res.has_value ());
645+ ASSERT_TRUE (Res.has_value ());
646+ ASSERT_TRUE (Res->hasRetAttr (Attribute::NoUndef));
647+ ASSERT_FALSE (Res->hasParamAttr (1 , Attribute::NoUndef));
614648
615649 AL1 = AL1.addParamAttribute (C, 2 , Attribute::NoUndef);
616650 Res = AL0.intersectWith (C, AL1);
617- ASSERT_FALSE (Res.has_value ());
651+ ASSERT_TRUE (Res.has_value ());
652+ ASSERT_TRUE (Res->hasRetAttr (Attribute::NoUndef));
653+ ASSERT_FALSE (Res->hasParamAttr (1 , Attribute::NoUndef));
654+ ASSERT_FALSE (Res->hasParamAttr (2 , Attribute::NoUndef));
618655
619656 AL0 = AL0.addParamAttribute (C, 2 , Attribute::NoUndef);
620657 AL1 = AL1.addParamAttribute (C, 1 , Attribute::NoUndef);
@@ -692,7 +729,17 @@ TEST(Attributes, ListIntersect) {
692729
693730 AL1 = AL1.addParamAttribute (C, 3 , Attribute::ReadNone);
694731 Res = AL0.intersectWith (C, AL1);
695- ASSERT_FALSE (Res.has_value ());
732+ ASSERT_TRUE (Res.has_value ());
733+ ASSERT_TRUE (Res.has_value ());
734+ ASSERT_TRUE (Res->hasFnAttr (Attribute::AlwaysInline));
735+ ASSERT_TRUE (Res->hasFnAttr (Attribute::ReadOnly));
736+ ASSERT_TRUE (Res->hasRetAttr (Attribute::NoUndef));
737+ ASSERT_FALSE (Res->hasRetAttr (Attribute::NonNull));
738+ ASSERT_TRUE (Res->hasParamAttr (1 , Attribute::NoUndef));
739+ ASSERT_TRUE (Res->hasParamAttr (2 , Attribute::NoUndef));
740+ ASSERT_FALSE (Res->hasParamAttr (2 , Attribute::NonNull));
741+ ASSERT_FALSE (Res->hasParamAttr (2 , Attribute::ReadNone));
742+ ASSERT_FALSE (Res->hasParamAttr (3 , Attribute::ReadNone));
696743
697744 AL0 = AL0.addParamAttribute (C, 3 , Attribute::ReadNone);
698745 Res = AL0.intersectWith (C, AL1);
0 commit comments