diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1693,11 +1693,23 @@ } void AttributeList::print(raw_ostream &O) const { - O << "PAL[\n"; + O << "AttributeList[\n"; for (unsigned i = index_begin(), e = index_end(); i != e; ++i) { - if (getAttributes(i).hasAttributes()) - O << " { " << i << " => " << getAsString(i) << " }\n"; + if (!getAttributes(i).hasAttributes()) + continue; + O << " { "; + switch (i) { + case AttrIndex::ReturnIndex: + O << "return"; + break; + case AttrIndex::FunctionIndex: + O << "function"; + break; + default: + O << "arg(" << i - AttrIndex::FirstArgIndex << ")"; + } + O << " => " << getAsString(i) << " }\n"; } O << "]\n"; diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1895,13 +1895,13 @@ if (AttributeListsVisited.insert(Attrs.getRawPointer()).second) { Assert(Attrs.hasParentContext(Context), - "Attribute list does not match Module context!", &Attrs); + "Attribute list does not match Module context!", &Attrs, V); for (const auto &AttrSet : Attrs) { Assert(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context), - "Attribute set does not match Module context!", &AttrSet); + "Attribute set does not match Module context!", &AttrSet, V); for (const auto &A : AttrSet) { Assert(A.hasParentContext(Context), - "Attribute does not match Module context!", &A); + "Attribute does not match Module context!", &A, V); } } } diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp --- a/llvm/unittests/IR/AttributesTest.cpp +++ b/llvm/unittests/IR/AttributesTest.cpp @@ -217,4 +217,39 @@ } } +TEST(Attributes, AttributeListPrinting) { + LLVMContext C; + + { + std::string S; + raw_string_ostream OS(S); + AttributeList AL; + AL.addAttribute(C, AttributeList::FunctionIndex, Attribute::AlwaysInline) + .print(OS); + EXPECT_EQ(S, "AttributeList[\n" + " { function => alwaysinline }\n" + "]\n"); + } + + { + std::string S; + raw_string_ostream OS(S); + AttributeList AL; + AL.addAttribute(C, AttributeList::ReturnIndex, Attribute::SExt).print(OS); + EXPECT_EQ(S, "AttributeList[\n" + " { return => signext }\n" + "]\n"); + } + + { + std::string S; + raw_string_ostream OS(S); + AttributeList AL; + AL.addParamAttribute(C, 5, Attribute::ZExt).print(OS); + EXPECT_EQ(S, "AttributeList[\n" + " { arg(5) => zeroext }\n" + "]\n"); + } +} + } // end anonymous namespace