Skip to content

Commit a4f4cbc

Browse files
committed
Fix AllTop-compose
1 parent 06e0215 commit a4f4cbc

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

include/phasar/DataFlow/IfdsIde/EdgeFunction.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,17 @@ class [[clang::trivial_abi]] EdgeFunction final : EdgeFunctionBase {
547547
return this->template isa<ConcreteEF>() ? getPtr<ConcreteEF>(EF) : nullptr;
548548
}
549549

550+
template <typename ConcreteEF>
551+
[[nodiscard]] std::optional<EdgeFunctionRef<ConcreteEF>>
552+
asRef() const noexcept {
553+
if (isa<ConcreteEF>()) {
554+
return EdgeFunctionRef<ConcreteEF>(
555+
EF, getAllocationPolicy() == AllocationPolicy::CustomHeapAllocated);
556+
}
557+
558+
return std::nullopt;
559+
}
560+
550561
// -- misc
551562

552563
/// True, iff this edge function is not small-object-optimized and thus its
@@ -738,17 +749,17 @@ class [[clang::trivial_abi]] EdgeFunction final : EdgeFunctionBase {
738749
namespace llvm {
739750

740751
template <typename L> struct DenseMapInfo<psr::EdgeFunction<L>> {
741-
static inline auto getEmptyKey() noexcept {
752+
static auto getEmptyKey() noexcept {
742753
return psr::EdgeFunction<L>::getEmptyKey();
743754
}
744-
static inline auto getTombstoneKey() noexcept {
755+
static auto getTombstoneKey() noexcept {
745756
return psr::EdgeFunction<L>::getTombstoneKey();
746757
}
747-
static inline auto getHashValue(const psr::EdgeFunction<L> &EF) noexcept {
758+
static auto getHashValue(const psr::EdgeFunction<L> &EF) noexcept {
748759
return EF.getHashCode();
749760
}
750-
static inline auto isEqual(const psr::EdgeFunction<L> &EF1,
751-
const psr::EdgeFunction<L> &EF2) noexcept {
761+
static auto isEqual(const psr::EdgeFunction<L> &EF1,
762+
const psr::EdgeFunction<L> &EF2) noexcept {
752763
if (EF1.referenceEquals(EF2)) {
753764
return true;
754765
}

include/phasar/DataFlow/IfdsIde/EdgeFunctionUtils.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ template <typename L> struct AllTop final {
173173
[[nodiscard]] static EdgeFunction<l_t>
174174
compose(EdgeFunctionRef<AllTop> This,
175175
const EdgeFunction<l_t> &SecondFunction) {
176-
return llvm::isa<EdgeIdentity<l_t>>(SecondFunction) ? This : SecondFunction;
176+
return SecondFunction.isConstant() ? SecondFunction : This;
177177
}
178178

179179
[[nodiscard]] static EdgeFunction<l_t>
@@ -211,13 +211,16 @@ defaultComposeOrNull(const EdgeFunction<L> &This,
211211
if (llvm::isa<EdgeIdentity<L>>(SecondFunction)) {
212212
return This;
213213
}
214-
if (SecondFunction.isConstant() || llvm::isa<AllTop<L>>(This) ||
215-
llvm::isa<EdgeIdentity<L>>(This)) {
214+
if (SecondFunction.isConstant() || llvm::isa<EdgeIdentity<L>>(This)) {
216215
return SecondFunction;
217216
}
218-
if (llvm::isa<AllBottom<L>>(This)) {
217+
if (llvm::isa<AllTop<L>>(This)) {
219218
return This;
220219
}
220+
if (auto BotEF = This.template asRef<AllBottom<L>>()) {
221+
return AllBottom<L>::compose(*BotEF, SecondFunction);
222+
}
223+
221224
return nullptr;
222225
}
223226

@@ -471,12 +474,10 @@ ConstantEdgeFunction<L>::compose(EdgeFunctionRef<ConcreteEF> This,
471474

472475
if constexpr (AreEqualityComparable<decltype(JLattice::top()), L>) {
473476
if (JLattice::top() == ConstVal) {
474-
/// TODO: Can this ever happen?
475477
return AllTop<L>{};
476478
}
477479
} else {
478480
if (L(JLattice::top()) == ConstVal) {
479-
/// TODO: Can this ever happen?
480481
return AllTop<L>{};
481482
}
482483
}
@@ -505,7 +506,7 @@ ConstantEdgeFunction<L>::join(EdgeFunctionRef<ConcreteEF> This,
505506
return OtherFunction.joinWith(This);
506507
}
507508

508-
auto OtherVal = OtherFunction.computeTarget(JLattice::top());
509+
auto OtherVal = OtherFunction.computeTarget(JLattice::bottom());
509510
auto JoinedVal = JLattice::join(This->Value, OtherVal);
510511

511512
if constexpr (AreEqualityComparable<decltype(JLattice::bottom()), l_t>) {

0 commit comments

Comments
 (0)