[PATCH] D68233: [FPEnv] [WIP] Verify strictfp attribute correctness

Kevin P. Neal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 12:20:11 PDT 2019


kpn updated this revision to Diff 225937.
kpn added a comment.

Add strict attribute checks to all function calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68233/new/

https://reviews.llvm.org/D68233

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ 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<Function &>(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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68233.225937.patch
Type: text/x-patch
Size: 3023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191021/6f998841/attachment.bin>


More information about the llvm-commits mailing list