From 017c14e722fb351bf9dcd9139992403dcabebe86 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 3 Sep 2014 23:24:31 +0000 Subject: [PATCH] Don't treat 0 as a special value for int attributes. Split the get() to not use a default value. This way attributes can be added that have 0 as a legitimate value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217107 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Attributes.h | 7 ++++--- lib/IR/Attributes.cpp | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h index 5ff48d68891..a6634cfdbe7 100644 --- a/include/llvm/IR/Attributes.h +++ b/include/llvm/IR/Attributes.h @@ -126,7 +126,8 @@ public: //===--------------------------------------------------------------------===// /// \brief Return a uniquified Attribute object. - static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0); + static Attribute get(LLVMContext &Context, AttrKind Kind); + static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val); static Attribute get(LLVMContext &Context, StringRef Kind, StringRef Val = StringRef()); @@ -273,13 +274,13 @@ public: /// \brief Remove the specified attribute at the specified index from this /// attribute list. Since attribute lists are immutable, this returns the new /// list. - AttributeSet removeAttribute(LLVMContext &C, unsigned Index, + AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const; /// \brief Remove the specified attributes at the specified index from this /// attribute list. Since attribute lists are immutable, this returns the new /// list. - AttributeSet removeAttributes(LLVMContext &C, unsigned Index, + AttributeSet removeAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const; //===--------------------------------------------------------------------===// diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 04545ea919a..a2f1dd0593c 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -31,12 +31,10 @@ using namespace llvm; // Attribute Construction Methods //===----------------------------------------------------------------------===// -Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, - uint64_t Val) { +Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind) { LLVMContextImpl *pImpl = Context.pImpl; FoldingSetNodeID ID; ID.AddInteger(Kind); - if (Val) ID.AddInteger(Val); void *InsertPoint; AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); @@ -44,10 +42,28 @@ Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, if (!PA) { // If we didn't find any existing attributes of the same shape then create a // new one and insert it. - if (!Val) - PA = new EnumAttributeImpl(Kind); - else - PA = new IntAttributeImpl(Kind, Val); + PA = new EnumAttributeImpl(Kind); + pImpl->AttrsSet.InsertNode(PA, InsertPoint); + } + + // Return the Attribute that we found or created. + return Attribute(PA); +} + +Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, + uint64_t Val) { + LLVMContextImpl *pImpl = Context.pImpl; + FoldingSetNodeID ID; + ID.AddInteger(Kind); + ID.AddInteger(Val); + + void *InsertPoint; + AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); + + if (!PA) { + // If we didn't find any existing attributes of the same shape then create a + // new one and insert it. + PA = new IntAttributeImpl(Kind, Val); pImpl->AttrsSet.InsertNode(PA, InsertPoint); }