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, 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; } 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(FPos); - // Every function might be "undefined-behavior" + // Every function might contain instructions that cause "undefined behavior". getOrCreateAAFor(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)