]> granicus.if.org Git - llvm/commitdiff
Fix crash in AttributeList::addAttributes, add test
authorReid Kleckner <rnk@google.com>
Tue, 18 Apr 2017 22:10:18 +0000 (22:10 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 18 Apr 2017 22:10:18 +0000 (22:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300614 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Attributes.cpp
unittests/IR/AttributesTest.cpp

index 2b7359dab807d1b865b7dfed28ccfb060b413620..3da00ad6fd4a51dc1f3b546e51d6d7c3504a40fb 100644 (file)
@@ -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.
index b5b221c63a173d20795e07b3977939e64fe09019..c9c8cb75ebf89dcebf599808bd161509f3b84bf2 100644 (file)
@@ -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