[PATCH] D71435: [WIP] [Attributor] Function level undefined behavior attribute

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 16:30:04 PST 2019


baziotis updated this revision to Diff 233705.
baziotis added a comment.

- Made AAUB function-only (i.e. no call-site, as AAReachability).
- Small fixes.

I'll come back with tests and updateImpl() (probably in reverse order, as otherwise tests are useless).


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

https://reviews.llvm.org/D71435

Files:
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/Attributor.cpp


Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1974,7 +1974,6 @@
 
     auto HandleLoadInstruction = [&](Instruction &I) {
       // TODO: Do something for every load instruction...
-      IRPosition IPos = IRPosition::callsite_function(ImmutableCallSite(&I));
       return true;
     };
     A.checkForAllInstructions(HandleLoadInstruction, *this,
@@ -1998,27 +1997,10 @@
 
   /// See AbstractAttribute::trackStatistics()
   void trackStatistics() const override {
-    STATS_DECLTRACK_CS_ATTR(undefinedbehavior)
-  }
-};
-
-struct AAUndefinedBehaviorCallSite final : AAUndefinedBehaviorImpl {
-  AAUndefinedBehaviorCallSite(const IRPosition &IRP)
-      : AAUndefinedBehaviorImpl(IRP) {}
-
-  /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override {
-    AAUndefinedBehaviorImpl::initialize(A);
-  }
-
-  /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override {
-    return indicatePessimisticFixpoint();
-  }
-
-  /// See AbstractAttribute::trackStatistics()
-  void trackStatistics() const override {
-    STATS_DECLTRACK_CS_ATTR(undefinedbehavior)
+    STATS_DECL(UndefinedBehaviorInstruction, Instruction,
+               "Number of instructions known to have UB");
+    // TODO: This should be AssumedUBInstructions.size();
+    BUILD_STAT_NAME(UndefinedBehaviorInstruction, Instruction) += 1;
   }
 };
 
@@ -5532,7 +5514,7 @@
   // Every function might be "will-return".
   getOrCreateAAFor<AAWillReturn>(FPos);
 
-  // Every function might be "undefined-behavior"
+  // Every function might contain instructions that cause "undefined behavior".
   getOrCreateAAFor<AAUndefinedBehavior>(FPos);
 
   // Every function can be nounwind.
@@ -5946,7 +5928,6 @@
 CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoSync)
 CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoRecurse)
 CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAWillReturn)
-CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAUndefinedBehavior)
 CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoReturn)
 CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAReturnedValues)
 
@@ -5962,6 +5943,7 @@
 
 CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAHeapToStack)
 CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAReachability)
+CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAUndefinedBehavior)
 
 CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMemoryBehavior)
 
Index: llvm/include/llvm/Transforms/IPO/Attributor.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/Attributor.h
+++ llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1682,17 +1682,17 @@
   static const char ID;
 };
 
-/// An abstract attribute for undefinedbehavior.
+/// An abstract attribute for undefined behavior.
 struct AAUndefinedBehavior
     : public StateWrapper<BooleanState, AbstractAttribute>,
       public IRPosition {
   AAUndefinedBehavior(const IRPosition &IRP) : IRPosition(IRP) {}
 
-  /// Return true if "undefinedbehavior" is assumed.
-  bool isAssumedAAUndefinedBehavior() const { return true; }
+  /// Return true if "undefined behavior" is assumed.
+  bool isAssumedToCauseUB() const { return getAssumed(); }
 
-  /// Return true if "undefinedbehavior" is known.
-  bool isKnownAAUndefinedBehavior() const { return false; }
+  /// Return true if "undefined behavior" is known.
+  bool isKnownToCauseUB() const { return getKnown(); }
 
   /// Return an IR position, see struct IRPosition.
   const IRPosition &getIRPosition() const override { return *this; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71435.233705.patch
Type: text/x-patch
Size: 3728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191213/1e773f04/attachment.bin>


More information about the llvm-commits mailing list