[llvm] r300614 - Fix crash in AttributeList::addAttributes, add test
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 15:10:18 PDT 2017
Author: rnk
Date: Tue Apr 18 17:10:18 2017
New Revision: 300614
URL: http://llvm.org/viewvc/llvm-project?rev=300614&view=rev
Log:
Fix crash in AttributeList::addAttributes, add test
Modified:
llvm/trunk/lib/IR/Attributes.cpp
llvm/trunk/unittests/IR/AttributesTest.cpp
Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=300614&r1=300613&r2=300614&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Tue Apr 18 17:10:18 2017
@@ -988,6 +988,9 @@ AttributeList AttributeList::addAttribut
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.
Modified: llvm/trunk/unittests/IR/AttributesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/AttributesTest.cpp?rev=300614&r1=300613&r2=300614&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/AttributesTest.cpp (original)
+++ llvm/trunk/unittests/IR/AttributesTest.cpp Tue Apr 18 17:10:18 2017
@@ -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
More information about the llvm-commits
mailing list