forked from secure-software-engineering/phasar
-
Notifications
You must be signed in to change notification settings - Fork 0
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 TypeHierarchy #18
Closed
Closed
Changes from 33 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
cd2300f
small backup safe
mxHuber 9428cb5
backup save, still needs metadata extraction
mxHuber 0d4d535
refactoring + some basic functions implemented
mxHuber 483596e
basic structure of constructHierarchy()
mxHuber 5d1a5d3
DIBasedTypeHierarchy structure
fabianbs96 0b9c1e8
basic impl of constructor and hasVFTable
mxHuber ac6495c
impl edges of graph, isSubType, getSubType and print
mxHuber e630e04
untested version of transitive closure
mxHuber 688c115
added transitive closure and changed print
mxHuber f8b48aa
fixed transitive closure + refactoring
mxHuber 587839f
bug fixes + tests
mxHuber deebbcf
debugging Debug info extraction
mxHuber a81ab3b
Fixed type extraction, untested transitive hull
mxHuber 36a0fa2
fixed includes + more debug info
mxHuber 00dace4
bug fixes and non recursive transitive hull
mxHuber d833748
working direct edge detection
mxHuber cd5d7a4
BitVector, cleanup, start of vtable impl
mxHuber 21bf49f
vtables and dotgraph
mxHuber 7451de3
review changes + vtable fix, 50% finished
mxHuber 71592b4
impl review suggestions
mxHuber 03aadf1
removed old type_hierarchy unittests
mxHuber 57eefb8
impl .set_bits() loop
mxHuber 518309b
fixed vtables
mxHuber 24a6cd0
fixes and code cleanup
mxHuber 61d18ff
added llvm::interleaveComma
mxHuber 7ea9969
fixed wrong assertion
mxHuber 0a60991
public LLVMVFTable constructor
mxHuber 027d843
small refactor
mxHuber 39756ac
important bugfixes
mxHuber 6ece219
unittests for multiple base classes
mxHuber 8bc4a30
unittests not finished, backup
mxHuber a7dd8ca
more unittests, all pass
mxHuber 0e61b48
reworked unittests
mxHuber fa093ef
review changes
mxHuber b1635c1
review changes
mxHuber c3c9b51
myphasartools.cpp revert
mxHuber 8669373
Merge remote-tracking branch 'refs/remotes/origin/development' into d…
mxHuber 15af897
current final version
mxHuber 29a0c12
Bump submodules
fabianbs96 af587b2
backup of fixes + unittests
mxHuber 1f1e323
more unittests
mxHuber 5b56d8c
new unittest
mxHuber 06dbc3f
Pin swift version
fabianbs96 6cdaaa7
basicRecoTH backup
mxHuber 7756202
backup of structure
mxHuber e6b87cd
new unittests, some fail
mxHuber a8ef03a
unittests fixed, all pass
mxHuber 4379bd0
Merge remote-tracking branch 'mainline/development' into f-Modernized…
fabianbs96 5f15a19
Add LLVM-RTTI-style type-hierarchy layout
fabianbs96 e616272
Merge branch 'development' into f-ModernizedLLVMTypeHierarchy
fabianbs96 9e215dc
Fix logging macro invocation
fabianbs96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/****************************************************************************** | ||
* 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 *; | ||
|
||
DIBasedTypeHierarchy(const LLVMProjectIRDB &IRDB); | ||
~DIBasedTypeHierarchy() override = default; | ||
|
||
[[nodiscard]] bool hasType([[maybe_unused]] ClassType Type) const override { | ||
return TypeToVertex.count(Type); | ||
} | ||
|
||
[[nodiscard]] bool isSubType(ClassType Type, ClassType SubType) override; | ||
|
||
[[nodiscard]] std::set<ClassType> getSubTypes(ClassType Type) override; | ||
|
||
[[nodiscard]] bool isSuperType(ClassType Type, ClassType SuperType) override; | ||
|
||
[[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]] std::deque<LLVMVFTable> getAllVTables() const { | ||
return {VTables.begin(), VTables.end()}; | ||
} | ||
|
||
[[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; | ||
|
||
[[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: | ||
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! | ||
llvm::DenseMap<ClassType, size_t> TypeToVertex; | ||
// The class types we care about ("VertexProperties") | ||
std::vector<ClassType> VertexTypes; | ||
// The type-graph edges ("Adjacency List"). | ||
// DerivedTypesOf[TypeToVertex.lookup(Ty)] gives the indices of the direct | ||
// subclasses of type T | ||
// The VTables of the polymorphic types in the TH. default-constructed if not | ||
// exists | ||
std::deque<LLVMVFTable> VTables; | ||
// Transitive closure implemented as a matrix | ||
// Example: | ||
// | ||
// Graph: Transitive closure: | ||
// (A) -> (C) | A B C | ||
// ^ --+------ | ||
// | A | 1 0 1 | ||
// (B) B | 1 1 1 | ||
// C | 0 0 1 | ||
std::vector<llvm::BitVector> TransitiveClosure; | ||
}; | ||
} // namespace psr | ||
|
||
#endif // PHASAR_PHASARLLVM_TYPEHIERARCHY_DIBASEDTYPEHIERARCHY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May use PhASAR's logger here instead