@@ -376,6 +376,12 @@ UWTableKind Attribute::getUWTableKind() const {
376376 return UWTableKind (pImpl->getValueAsInt ());
377377}
378378
379+ AllocFnKind Attribute::getAllocKind () const {
380+ assert (hasAttribute (Attribute::AllocKind) &&
381+ " Trying to get allockind value from non-allockind attribute" );
382+ return AllocFnKind (pImpl->getValueAsInt ());
383+ }
384+
379385std::string Attribute::getAsString (bool InAttrGrp) const {
380386 if (!pImpl) return {};
381387
@@ -447,6 +453,26 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
447453 }
448454 }
449455
456+ if (hasAttribute (Attribute::AllocKind)) {
457+ AllocFnKind Kind = getAllocKind ();
458+ SmallVector<StringRef> parts;
459+ if ((Kind & AllocFnKind::Alloc) != AllocFnKind::Unknown)
460+ parts.push_back (" alloc" );
461+ if ((Kind & AllocFnKind::Realloc) != AllocFnKind::Unknown)
462+ parts.push_back (" realloc" );
463+ if ((Kind & AllocFnKind::Free) != AllocFnKind::Unknown)
464+ parts.push_back (" free" );
465+ if ((Kind & AllocFnKind::Uninitialized) != AllocFnKind::Unknown)
466+ parts.push_back (" uninitialized" );
467+ if ((Kind & AllocFnKind::Zeroed) != AllocFnKind::Unknown)
468+ parts.push_back (" zeroed" );
469+ if ((Kind & AllocFnKind::Aligned) != AllocFnKind::Unknown)
470+ parts.push_back (" aligned" );
471+ return (" allockind(\" " +
472+ Twine (llvm::join (parts.begin (), parts.end (), " ," )) + " \" )" )
473+ .str ();
474+ }
475+
450476 // Convert target-dependent attributes to strings of the form:
451477 //
452478 // "kind"
@@ -735,6 +761,10 @@ UWTableKind AttributeSet::getUWTableKind() const {
735761 return SetNode ? SetNode->getUWTableKind () : UWTableKind::None;
736762}
737763
764+ AllocFnKind AttributeSet::getAllocKind () const {
765+ return SetNode ? SetNode->getAllocKind () : AllocFnKind::Unknown;
766+ }
767+
738768std::string AttributeSet::getAsString (bool InAttrGrp) const {
739769 return SetNode ? SetNode->getAsString (InAttrGrp) : " " ;
740770}
@@ -907,6 +937,12 @@ UWTableKind AttributeSetNode::getUWTableKind() const {
907937 return UWTableKind::None;
908938}
909939
940+ AllocFnKind AttributeSetNode::getAllocKind () const {
941+ if (auto A = findEnumAttribute (Attribute::AllocKind))
942+ return A->getAllocKind ();
943+ return AllocFnKind::Unknown;
944+ }
945+
910946std::string AttributeSetNode::getAsString (bool InAttrGrp) const {
911947 std::string Str;
912948 for (iterator I = begin (), E = end (); I != E; ++I) {
@@ -1463,6 +1499,10 @@ UWTableKind AttributeList::getUWTableKind() const {
14631499 return getFnAttrs ().getUWTableKind ();
14641500}
14651501
1502+ AllocFnKind AttributeList::getAllocKind () const {
1503+ return getFnAttrs ().getAllocKind ();
1504+ }
1505+
14661506std::string AttributeList::getAsString (unsigned Index, bool InAttrGrp) const {
14671507 return getAttributes (Index).getAsString (InAttrGrp);
14681508}
@@ -1690,6 +1730,10 @@ AttrBuilder &AttrBuilder::addUWTableAttr(UWTableKind Kind) {
16901730 return addRawIntAttr (Attribute::UWTable, uint64_t (Kind));
16911731}
16921732
1733+ AttrBuilder &AttrBuilder::addAllocKindAttr (AllocFnKind Kind) {
1734+ return addRawIntAttr (Attribute::AllocKind, static_cast <uint64_t >(Kind));
1735+ }
1736+
16931737Type *AttrBuilder::getTypeAttr (Attribute::AttrKind Kind) const {
16941738 assert (Attribute::isTypeAttrKind (Kind) && " Not a type attribute" );
16951739 Attribute A = getAttribute (Kind);
0 commit comments