diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -277,6 +277,10 @@ /// already. bool SawFrameEscape; + /// Whether or not we've seen constrained floating-point intrinsics + /// in a function. + bool HasConstrainedFP; + /// Whether the current function has a DISubprogram attached to it. bool HasDebugInfo = false; @@ -347,9 +351,11 @@ } Broken = false; + HasConstrainedFP = false; // FIXME: We strip const here because the inst visitor strips const. visit(const_cast(F)); verifySiblingFuncletUnwinds(); + verifyFunctionConstrainedFP(F); InstsInThisBlock.clear(); DebugFnArgs.clear(); LandingPadResultTy = nullptr; @@ -493,6 +499,7 @@ void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch); void visitCleanupReturnInst(CleanupReturnInst &CRI); + void verifyFunctionConstrainedFP(const Function &F); void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal); void verifySwiftErrorValue(const Value *SwiftErrorVal); void verifyMustTailCall(CallInst &CI); @@ -2369,6 +2376,17 @@ } } + +void Verifier::verifyFunctionConstrainedFP(const Function &F) { + if (HasConstrainedFP) { + AttributeList Attrs = F.getAttributes(); + AttributeSet FnAttrs = Attrs.getFnAttributes(); + Assert (FnAttrs.hasAttribute(Attribute::StrictFP), + "Constrained floating point requires function attribute strictfp!", + &F); + } +} + // verifyBasicBlock - Verify that a basic block is well formed... // void Verifier::visitBasicBlock(BasicBlock &BB) { @@ -2862,6 +2880,16 @@ // Verify call attributes. verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic); + // Verify strictfp attributes match. + Function *ContainingF = Call.getFunction(); + AttributeSet CFnAttrs = ContainingF->getAttributes().getFnAttributes(); + AttributeSet CallAttrs = Attrs.getFnAttributes(); + Assert (CFnAttrs.hasAttribute(Attribute::StrictFP) == + CallAttrs.hasAttribute(Attribute::StrictFP), + "Functions and their contained calls must match " + "in use of attribute strictfp!", + ContainingF, &Call); + // Conservatively check the inalloca argument. // We have a bug if we can find that there is an underlying alloca without // inalloca. @@ -4745,6 +4773,7 @@ unsigned NumOperands = FPI.getNumArgOperands(); bool HasExceptionMD = false; bool HasRoundingMD = false; + HasConstrainedFP = true; switch (FPI.getIntrinsicID()) { case Intrinsic::experimental_constrained_sqrt: case Intrinsic::experimental_constrained_sin: