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 TypeHierarchy #18

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
51 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
e6b87cd
new unittests, some fail
mxHuber Oct 17, 2023
a8ef03a
unittests fixed, all pass
mxHuber Oct 18, 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
e616272
Merge branch 'development' into f-ModernizedLLVMTypeHierarchy
fabianbs96 Feb 2, 2024
9e215dc
Fix logging macro invocation
fabianbs96 Feb 5, 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
111 changes: 111 additions & 0 deletions include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h
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
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
2 changes: 2 additions & 0 deletions lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void LLVMTaintConfig::addAllFunctions(const LLVMProjectIRDB &IRDB,
const auto Sinks = Idx.get<std::string>();
if (Sinks == "all") {
for (const auto &Arg : Fun->args()) {
llvm::outs() << "Current arg: " << Arg << "\n";
llvm::outs().flush();
Copy link
Owner Author

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

addTaintCategory(&Arg, TaintCategory::Sink);
}
}
Expand Down
Loading