From: Reid Kleckner Date: Tue, 18 Apr 2017 22:10:18 +0000 (+0000) Subject: Fix crash in AttributeList::addAttributes, add test X-Git-Tag: llvmorg-5.0.0-rc1~7397 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe64c0137e69a7d4c7d9c451357b1216d5ff6bed;p=platform%2Fupstream%2Fllvm.git Fix crash in AttributeList::addAttributes, add test llvm-svn: 300614 --- diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 2b7359d..3da00ad 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -988,6 +988,9 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, if (!AS.hasAttributes()) return *this; + if (!pImpl) + return AttributeList::get(C, {{Index, AS}}); + #ifndef NDEBUG // FIXME it is not obvious how this should work for alignment. For now, say // we can't change a known alignment. diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp index b5b221c..c9c8cb7 100644 --- a/llvm/unittests/IR/AttributesTest.cpp +++ b/llvm/unittests/IR/AttributesTest.cpp @@ -49,4 +49,13 @@ TEST(Attributes, Ordering) { EXPECT_NE(SetA, SetB); } +TEST(Attributes, AddAttributes) { + LLVMContext C; + AttributeList AL; + AttrBuilder B; + B.addAttribute(Attribute::NoReturn); + AL = AL.addAttributes(C, AttributeList::FunctionIndex, AttributeSet::get(C, B)); + EXPECT_TRUE(AL.hasFnAttribute(Attribute::NoReturn)); +} + } // end anonymous namespace