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); @@ -2370,6 +2377,19 @@ } } +// Verify that the function has the correct attributes if a constrained +// floating-point value was seen. +// +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) { @@ -2863,6 +2883,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. @@ -4752,6 +4782,10 @@ unsigned NumOperands = FPI.getNumArgOperands(); bool HasExceptionMD = false; bool HasRoundingMD = false; + HasConstrainedFP = true; + AttributeSet CallAttrs = FPI.getAttributes().getFnAttributes(); + Assert (CallAttrs.hasAttribute(Attribute::StrictFP), + "Constrained FP intrinsics require strictfp attribute.", &FPI); switch (FPI.getIntrinsicID()) { case Intrinsic::experimental_constrained_sqrt: case Intrinsic::experimental_constrained_sin: