[PATCH] D70451: [FPEnv] IRBuilder should not put strictfp on function definitions automatically

Kevin P. Neal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 19 10:06:36 PST 2019


kpn created this revision.
kpn added reviewers: spatel, rjmccall, andrew.w.kaylor.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The IRBuilder will currently automatically put the strictfp attribute on a function definition if strictfp mode is enabled and a function call is emitted. It turns out that this is incorrect since the IRBuilder is currently being used to add instructions to BasicBlocks that do _not_ have a Function. A segv is the result.

The new rule is that the front end must be the one to set the attribute on a function definition. Period. No attempt is made to be clever about trying to handle this in the IRBuilder automatically since it cannot be done with 100% reliably as far as I know.

This ticket is needed to unblock D62731 <https://reviews.llvm.org/D62731>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70451

Files:
  llvm/include/llvm/IR/IRBuilder.h
  llvm/unittests/IR/IRBuilderTest.cpp


Index: llvm/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ 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);
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ 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();
   }
 
   //===--------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70451.230095.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191119/37f057af/attachment.bin>


More information about the llvm-commits mailing list