Files
revng-revng/lib/DataLayoutAnalysis/Middleend/RemoveInvalidPointers.cpp
T
Giacomo Vercesi ab125b35b0 Fix License headers
Change company name to "rev.ng Labs Srl" in all license headers
to reflect changed company name and legal status
Add missing license headers to files that didn't have one
2022-04-19 12:17:59 +02:00

43 lines
1.2 KiB
C++

//
// Copyright (c) rev.ng Labs Srl. See LICENSE.md for details.
//
#include "DLAStep.h"
bool dla::RemoveInvalidPointers::runOnTypeSystem(LayoutTypeSystem &TS) {
bool Changed = false;
for (LayoutTypeSystemNode *PtrNode : llvm::nodes(&TS)) {
// Nodes whose size is the same of a pointer cannot have invalid outgoind
// pointer edges.
if (PtrNode->Size == PointerSize)
continue;
auto It = PtrNode->Successors.begin();
auto End = PtrNode->Successors.end();
auto Next = End;
for (; It != End; It = Next) {
Next = std::next(It);
// Ignore non-pointer edges
if (not isPointerEdge(*It))
continue;
// If we reach this point PtrNode->Size is different from a pointer size
// and It points to a pointer edge that is outgoing from PtrNode.
// That edge is invalid, because according to PtrNode->Size PtrNode cannot
// be a pointer, so we remove the wrong edge.
LayoutTypeSystemNode *Pointee = It->first;
auto PredIt = Pointee->Predecessors.find({ PtrNode, It->second });
revng_assert(PredIt != Pointee->Predecessors.end());
Pointee->Predecessors.erase(PredIt);
PtrNode->Successors.erase(It);
Changed = true;
}
}
return Changed;
}