diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -259,6 +259,7 @@ assert(BB && "Must have a basic block to set any function attributes!"); Function *F = BB->getParent(); + assert(F && "Must have a function to set any function attributes!"); if (!F->hasFnAttribute(Attribute::StrictFP)) { F->addFnAttr(Attribute::StrictFP); } @@ -267,7 +268,6 @@ void setConstrainedFPCallAttr(CallInst *I) { if (!I->hasFnAttr(Attribute::StrictFP)) I->addAttribute(AttributeList::FunctionIndex, Attribute::StrictFP); - setConstrainedFPFunctionAttr(); } //===--------------------------------------------------------------------===// diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -233,7 +233,8 @@ AttributeSet CallAttrs = II->getAttributes().getFnAttributes(); EXPECT_EQ(CallAttrs.hasAttribute(Attribute::StrictFP), true); - // Verify attributes on the containing function are created automatically. + // Verify attributes on the containing function are created when requested. + Builder.setConstrainedFPFunctionAttr(); AttributeList Attrs = BB->getParent()->getAttributes(); AttributeSet FnAttrs = Attrs.getFnAttributes(); EXPECT_EQ(FnAttrs.hasAttribute(Attribute::StrictFP), true);