Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI-based LLVM Type Hierarchy #702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cd2300f
small backup safe
mxHuber May 23, 2023
9428cb5
backup save, still needs metadata extraction
mxHuber May 30, 2023
0d4d535
refactoring + some basic functions implemented
mxHuber Jun 1, 2023
483596e
basic structure of constructHierarchy()
mxHuber Jun 2, 2023
5d1a5d3
DIBasedTypeHierarchy structure
fabianbs96 Jun 2, 2023
0b9c1e8
basic impl of constructor and hasVFTable
mxHuber Jun 5, 2023
ac6495c
impl edges of graph, isSubType, getSubType and print
mxHuber Jun 5, 2023
e630e04
untested version of transitive closure
mxHuber Jun 9, 2023
688c115
added transitive closure and changed print
mxHuber Jun 12, 2023
f8b48aa
fixed transitive closure + refactoring
mxHuber Jun 14, 2023
587839f
bug fixes + tests
mxHuber Jun 19, 2023
deebbcf
debugging Debug info extraction
mxHuber Jun 21, 2023
a81ab3b
Fixed type extraction, untested transitive hull
mxHuber Jun 21, 2023
36a0fa2
fixed includes + more debug info
mxHuber Jun 22, 2023
00dace4
bug fixes and non recursive transitive hull
mxHuber Jun 24, 2023
d833748
working direct edge detection
mxHuber Jun 25, 2023
cd5d7a4
BitVector, cleanup, start of vtable impl
mxHuber Jun 26, 2023
21bf49f
vtables and dotgraph
mxHuber Jun 27, 2023
7451de3
review changes + vtable fix, 50% finished
mxHuber Jun 28, 2023
71592b4
impl review suggestions
mxHuber Jun 29, 2023
03aadf1
removed old type_hierarchy unittests
mxHuber Jun 30, 2023
57eefb8
impl .set_bits() loop
mxHuber Jun 30, 2023
518309b
fixed vtables
mxHuber Jul 5, 2023
24a6cd0
fixes and code cleanup
mxHuber Jul 5, 2023
61d18ff
added llvm::interleaveComma
mxHuber Jul 5, 2023
7ea9969
fixed wrong assertion
mxHuber Jul 5, 2023
0a60991
public LLVMVFTable constructor
mxHuber Jul 6, 2023
027d843
small refactor
mxHuber Jul 12, 2023
39756ac
important bugfixes
mxHuber Jul 14, 2023
6ece219
unittests for multiple base classes
mxHuber Aug 22, 2023
8bc4a30
unittests not finished, backup
mxHuber Aug 22, 2023
a7dd8ca
more unittests, all pass
mxHuber Aug 23, 2023
0e61b48
reworked unittests
mxHuber Aug 31, 2023
fa093ef
review changes
mxHuber Sep 4, 2023
b1635c1
review changes
mxHuber Sep 6, 2023
c3c9b51
myphasartools.cpp revert
mxHuber Sep 6, 2023
8669373
Merge remote-tracking branch 'refs/remotes/origin/development' into d…
mxHuber Sep 20, 2023
15af897
current final version
mxHuber Sep 20, 2023
29a0c12
Bump submodules
fabianbs96 Sep 21, 2023
af587b2
backup of fixes + unittests
mxHuber Sep 22, 2023
1f1e323
more unittests
mxHuber Sep 29, 2023
5b56d8c
new unittest
mxHuber Sep 29, 2023
06dbc3f
Pin swift version
fabianbs96 Sep 30, 2023
6cdaaa7
basicRecoTH backup
mxHuber Oct 13, 2023
7756202
backup of structure
mxHuber Oct 13, 2023
9179cf0
Analysis Printer (#17)
fabianbs96 Oct 17, 2023
e6b87cd
new unittests, some fail
mxHuber Oct 17, 2023
a8ef03a
unittests fixed, all pass
mxHuber Oct 18, 2023
3062f3d
Merge branch 'development' into development
fabianbs96 Nov 6, 2023
70e3241
Merge branch 'development' into development
fabianbs96 Nov 14, 2023
4379bd0
Merge remote-tracking branch 'mainline/development' into f-Modernized…
fabianbs96 Nov 19, 2023
5f15a19
Add LLVM-RTTI-style type-hierarchy layout
fabianbs96 Nov 19, 2023
771d7d1
Merge branch 'development' into development
fabianbs96 Nov 19, 2023
6063730
fix: review feedback
sritejakv Nov 20, 2023
2e9efb0
Merge pull request #22 from fabianbs96/f-AnalysisPrinterReview
fabianbs96 Nov 20, 2023
a75309e
Merge branch 'development' into development
fabianbs96 Nov 25, 2023
e244eea
Merge branch 'secure-software-engineering:development' into development
fabianbs96 Nov 25, 2023
27c4c49
Merge remote-tracking branch 'mainline/development' into development
fabianbs96 Feb 2, 2024
e616272
Merge branch 'development' into f-ModernizedLLVMTypeHierarchy
fabianbs96 Feb 2, 2024
9e215dc
Fix logging macro invocation
fabianbs96 Feb 5, 2024
dc95906
Merge branch 'development' into f-ModernizedLLVMTypeHierarchy
fabianbs96 Feb 25, 2024
0b8f638
Split giant DIBasedTypeHierarchy ctor into multiple functions
fabianbs96 Feb 29, 2024
0139f16
Merge branch 'development' into f-ModernizedLLVMTypeHierarchy
MMory Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/******************************************************************************
* Copyright (c) 2023 Fabian Schiebel.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Fabian Schiebel and others
*****************************************************************************/

#ifndef PHASAR_PHASARLLVM_TYPEHIERARCHY_DIBASEDTYPEHIERARCHY_H
#define PHASAR_PHASARLLVM_TYPEHIERARCHY_DIBASEDTYPEHIERARCHY_H

#include "phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h"
#include "phasar/TypeHierarchy/TypeHierarchy.h"

#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"

#include <deque>

namespace psr {
class LLVMProjectIRDB;

class DIBasedTypeHierarchy
: public TypeHierarchy<const llvm::DIType *, const llvm::Function *> {
public:
using ClassType = const llvm::DIType *;
using f_t = const llvm::Function *;

explicit DIBasedTypeHierarchy(const LLVMProjectIRDB &IRDB);
~DIBasedTypeHierarchy() override = default;

[[nodiscard]] bool hasType(ClassType Type) const override {
return TypeToVertex.count(Type);
}

[[nodiscard]] bool isSubType(ClassType Type, ClassType SubType) override {
return llvm::is_contained(subTypesOf(Type), SubType);
}

[[nodiscard]] std::set<ClassType> getSubTypes(ClassType Type) override {
const auto &Range = subTypesOf(Type);
return {Range.begin(), Range.end()};
}

/// A more efficient version of getSubTypes()
[[nodiscard]] llvm::iterator_range<const ClassType *>
subTypesOf(ClassType Ty) const noexcept;

[[nodiscard]] bool isSuperType(ClassType Type, ClassType SuperType) override;

/// Not supported yet
[[nodiscard]] std::set<ClassType> getSuperTypes(ClassType Type) override;

[[nodiscard]] ClassType
getType(std::string TypeName) const noexcept override {
return NameToType.lookup(TypeName);
}

[[nodiscard]] std::set<ClassType> getAllTypes() const override {
return {VertexTypes.begin(), VertexTypes.end()};
}

[[nodiscard]] const auto &getAllVTables() const noexcept { return VTables; }

[[nodiscard]] std::string getTypeName(ClassType Type) const override {
return Type->getName().str();
}

[[nodiscard]] bool hasVFTable(ClassType Type) const override;

[[nodiscard]] const VFTable<f_t> *getVFTable(ClassType Type) const override {
auto It = TypeToVertex.find(Type);
if (It == TypeToVertex.end()) {
return nullptr;
}
return &VTables[It->second];
}

[[nodiscard]] size_t size() const override { return VertexTypes.size(); }

[[nodiscard]] bool empty() const override { return VertexTypes.empty(); }

void print(llvm::raw_ostream &OS = llvm::outs()) const override;

/**
* @brief Prints the class hierarchy to an ostream in dot format.
* @param OS outputstream
*/
void printAsDot(llvm::raw_ostream &OS = llvm::outs()) const;

[[nodiscard]] nlohmann::json getAsJson() const override;

private:
[[nodiscard]] llvm::iterator_range<const ClassType *>
subTypesOf(size_t TypeIdx) const noexcept;

// ---

llvm::StringMap<ClassType> NameToType;
// Map each type to an integer index that is used by VertexTypes and
// DerivedTypesOf.
// Note: all the below arrays should always have the same size (except for
// Hierarchy)!
llvm::DenseMap<ClassType, size_t> TypeToVertex;
// The class types we care about ("VertexProperties")
std::vector<const llvm::DICompositeType *> VertexTypes;
std::vector<std::pair<uint32_t, uint32_t>> TransitiveDerivedIndex;
// The inheritance graph linearized as-if constructed by L2R pre-order
// traversal from the roots. Allows efficient access to the transitive closure
// without ever storing it explicitly. This only works, because the type-graph
// is known to never contain loops
std::vector<ClassType> Hierarchy;

// The VTables of the polymorphic types in the TH. default-constructed if not
// exists
std::deque<LLVMVFTable> VTables;
};
} // namespace psr

#endif // PHASAR_PHASARLLVM_TYPEHIERARCHY_DIBASEDTYPEHIERARCHY_H
3 changes: 2 additions & 1 deletion include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ namespace psr {
class LLVMVFTable : public VFTable<const llvm::Function *> {
private:
friend class LLVMTypeHierarchy;
friend class DIBasedTypeHierarchy;
std::vector<const llvm::Function *> VFT;
LLVMVFTable(std::vector<const llvm::Function *> Fs) : VFT(std::move(Fs)) {}

public:
LLVMVFTable() = default;
LLVMVFTable(std::vector<const llvm::Function *> Fs) : VFT(std::move(Fs)) {}
~LLVMVFTable() override = default;

/**
Expand Down
Loading
Loading