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 @@ -294,8 +294,7 @@ } void setConstrainedFPCallAttr(CallInst *I) { - if (!I->hasFnAttr(Attribute::StrictFP)) - I->addAttribute(AttributeList::FunctionIndex, Attribute::StrictFP); + I->addAttribute(AttributeList::FunctionIndex, Attribute::StrictFP); } void setDefaultOperandBundles(ArrayRef OpBundles) { 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 @@ -332,6 +332,33 @@ EXPECT_EQ(fp::ebStrict, CII->getExceptionBehavior()); } +TEST_F(IRBuilderTest, ConstrainedFPFunctionCall) { + IRBuilder<> Builder(BB); + + // Create an empty constrained FP function. + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), + /*isVarArg=*/false); + Function *Callee = + Function::Create(FTy, Function::ExternalLinkage, "", M.get()); + BasicBlock *CalleeBB = BasicBlock::Create(Ctx, "", Callee); + IRBuilder<> CalleeBuilder(CalleeBB); + CalleeBuilder.setIsFPConstrained(true); + CalleeBuilder.setConstrainedFPFunctionAttr(); + CalleeBuilder.CreateRetVoid(); + + // Now call the empty constrained FP function. + Builder.setIsFPConstrained(true); + Builder.setConstrainedFPFunctionAttr(); + CallInst *FCall = Builder.CreateCall(Callee, None); + + // Check the attributes to verify the strictfp attribute is on the call. + EXPECT_TRUE(FCall->getAttributes().getFnAttributes().hasAttribute( + Attribute::StrictFP)); + + Builder.CreateRetVoid(); + EXPECT_FALSE(verifyModule(*M)); +} + TEST_F(IRBuilderTest, Lifetime) { IRBuilder<> Builder(BB); AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty());