Skip to content

Opaque Pointers Integration #730

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d2c7bcb
replaced llvm-14 with llvm-15 in relevant files
mxHuber May 15, 2024
ab3fa86
annotation fix + test fix
mxHuber May 29, 2024
f703041
removed bitcasts and fixed tests
mxHuber Jun 3, 2024
b78d077
Fix Annotation.cpp + TaintConfigTest
fabianbs96 Jun 4, 2024
09e34aa
Quick-fix LLVMTypeHierarchyTest
fabianbs96 Jun 4, 2024
147ecd1
fix one IIA test
fabianbs96 Jun 4, 2024
fda53ef
Fix StringtestCpp for generalized LCA
fabianbs96 Jun 4, 2024
9b449d1
first half of tests fixed
mxHuber Jun 5, 2024
6b12b7b
fixed first half of tests
mxHuber Jun 5, 2024
bbe775a
fixed all but one test in IDEInstInteractionAnalysisTest
mxHuber Jun 6, 2024
c235afc
fixed all but two tests
mxHuber Jun 6, 2024
311cb68
Fix IIAFlowFact equality
fabianbs96 Jun 7, 2024
04a895d
fixed some newly failed tests
mxHuber Jun 12, 2024
e31c5ae
trade soundness for precision in LLVMAliasSet
fabianbs96 Jun 12, 2024
b6f4a10
Merge remote-tracking branch 'upstream/development' into f-clang-15
mxHuber Jun 12, 2024
e8c7f65
ci.yml update
mxHuber Jun 12, 2024
c3081ed
Revert "fixed some newly failed tests"
mxHuber Jun 12, 2024
6ced614
pre-commit hook
mxHuber Jun 12, 2024
12a9d06
Two Tests + xtaint09 test fix for pipeline
mxHuber Jun 12, 2024
9f5902a
Basic Opaque Pointer Impl, bugged
mxHuber Jun 13, 2024
812e6cb
switching to DebugInfoFinder
mxHuber Jun 13, 2024
8f89d1d
re-add the quick-fix for LLVMTypeHierarchy
fabianbs96 Jun 16, 2024
2bfffa8
OpaquePtr type mapping, missing subroutines
mxHuber Jun 17, 2024
2a91b6d
Introducing a pass to save ptr types
mxHuber Jun 18, 2024
d581987
Revert "Introducing a pass to save ptr types"
mxHuber Jun 19, 2024
9eb9929
moving phasar to DIBasedTypeHierarchy
mxHuber Jun 19, 2024
0b7575e
full switch to DIBasedTypeHierarchy + Test fixes
mxHuber Jun 23, 2024
5b39a18
fixed PathTracingTest
mxHuber Jun 25, 2024
85b0f24
dtaresolver deprecated and test fixes
mxHuber Jul 1, 2024
16c4a8e
Fixed OTFTest
mxHuber Jul 1, 2024
0514c7d
trimmed trailing whitespace
mxHuber Jul 1, 2024
2d8c9d8
minor fixes
mxHuber Jul 10, 2024
4463625
readded TypeToDIType map for RTAResolver
mxHuber Jul 10, 2024
df7d190
pre-commit clang-format fix
mxHuber Jul 10, 2024
ce2c6e8
pre-commit clang-format llvmbasedicfg.cpp
mxHuber Jul 10, 2024
8a4d812
moved RTAResolver to DITypes
mxHuber Jul 10, 2024
fd11ada
implemented review suggestions
mxHuber Aug 4, 2024
9c7f378
Log error if trying to instantiate DTAResolver + minor
fabianbs96 Aug 6, 2024
022b426
Add breaking changes
fabianbs96 Aug 6, 2024
d482f4d
Merge branch 'development' into f-clang-15
fabianbs96 Aug 8, 2024
b4783b9
Also compare gep type in IIA EqualGEPDescriptor
fabianbs96 Aug 9, 2024
49707eb
Merge branch 'development' into f-clang-15
fabianbs96 Aug 9, 2024
3848eef
Merge branch 'development' into f-clang-15
fabianbs96 Oct 4, 2024
0cc3c7f
Merge branch 'development' into f-clang-15
fabianbs96 Oct 24, 2024
70cdc6b
debugging CI
fabianbs96 Oct 24, 2024
417e584
debugging
fabianbs96 Oct 24, 2024
e5bc4c8
DITH fix attempt for CI
fabianbs96 Oct 24, 2024
7c2a330
Merge branch 'development' into f-clang-15
fabianbs96 Nov 28, 2024
02d27e8
fix build
fabianbs96 Nov 29, 2024
c6a6758
Start adding more sophisticated type extraction (WIP)
fabianbs Oct 7, 2024
2723068
Handle function calls in getVarTypeFromIR
fabianbs96 Oct 8, 2024
ecdc7c5
better fallback handling for getDebugLocation, etc
fabianbs96 Oct 8, 2024
d410c3c
cleanup getVarTypeFromIR
fabianbs96 Feb 6, 2025
c5e6859
Merge branch 'development' into f-clang-15
fabianbs96 Feb 6, 2025
b2c5cf9
Merge branch 'development' into f-clang-15
fabianbs96 Feb 14, 2025
66c2b6f
Merge branch 'development' into f-clang-15
fabianbs96 Feb 22, 2025
70874e9
Merge branch 'development' into f-clang-15
fabianbs96 Mar 3, 2025
f42adc9
Merge branch 'development' into f-clang-15
fabianbs96 Mar 4, 2025
fb28587
Add libzstd-dev as apt dependency; otherwise the docker build fails o…
fabianbs96 Mar 4, 2025
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
2 changes: 2 additions & 0 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## development HEAD

- The `DTAResolver` and the cli option `--call-graph-analysis=dta` do not work anymore (due to opaque pointers) and will be removed for the next release. Please use the `OTF` or `RTA` resolver instead.
- The default type-hierarchy implementation has been changed from `LLVMTypeHierarchy` to `DIBasedTypeHierarchy`. This also requires all affected analyses to be performed on LLVM IR that contains debug information.
- Removed the phasar-library `phasar_controller`. It is now part of the tool `phasar-cli`.
- The API of the `TypeHierarchy` interface (and thus the `LLVMTypeHierarchy` and `DIBasedTypeHierarchy` as well) has changed:
- No handling of the super-type relation (only sub-types)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM

# LLVM
if (NOT PHASAR_LLVM_VERSION)
set(PHASAR_LLVM_VERSION 14)
set(PHASAR_LLVM_VERSION 15)
endif()
include(add_llvm)
add_llvm()
Expand Down
4 changes: 2 additions & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ source ./utils/safeCommandsSet.sh

readonly PHASAR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PHASAR_INSTALL_DIR="/usr/local/phasar"
LLVM_INSTALL_DIR="/usr/local/llvm-14"
LLVM_INSTALL_DIR="/usr/local/llvm-15"

NUM_THREADS=$(nproc)
LLVM_RELEASE=llvmorg-14.0.6
LLVM_RELEASE=llvmorg-15.0.7
DO_UNIT_TEST=true
DO_INSTALL=false
BUILD_TYPE=Release
Expand Down
13 changes: 1 addition & 12 deletions cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,6 @@ function(generate_ll_file)
set(GEN_C_FLAGS -fno-discard-value-names -emit-llvm -S -w)
set(GEN_CMD_COMMENT "[LL]")

string(REGEX MATCH "clang\\+*-?[0-9]*$" compiler "${CMAKE_CXX_COMPILER}")
if (compiler)
if(PHASAR_LLVM_VERSION GREATER_EQUAL 15)
list(APPEND GEN_CXX_FLAGS -Xclang -no-opaque-pointers)
endif()

if(PHASAR_LLVM_VERSION GREATER_EQUAL 15)
list(APPEND GEN_C_FLAGS -Xclang -no-opaque-pointers)
endif()
endif()

if(GEN_LL_MEM2REG)
list(APPEND GEN_CXX_FLAGS -Xclang -disable-O0-optnone)
list(APPEND GEN_C_FLAGS -Xclang -disable-O0-optnone)
Expand Down Expand Up @@ -219,7 +208,7 @@ function(generate_ll_file)
add_custom_command(
OUTPUT ${test_code_ll_file}
COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file}
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} ${opt} -mem2reg -S -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file}
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} ${opt} -mem2reg -S ${test_code_ll_file} -o ${test_code_ll_file}
COMMENT ${GEN_CMD_COMMENT}
DEPENDS ${GEN_LL_FILE}
VERBATIM
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class IDESolver
llvm::StringRef(NToString(Cells[I].getRowKey())).trim().str();

std::string NodeStr =
ICF->getFunctionName(ICF->getFunctionOf(Curr)) + "::" + NStr;
ICF->getFunctionName(ICF->getFunctionOf(Curr)).str() + "::" + NStr;
J[DataFlowID][NodeStr];
std::string FactStr =
llvm::StringRef(DToString(Cells[I].getColumnKey())).trim().str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
namespace psr {
class LLVMProjectIRDB;
enum class CallGraphAnalysisType;
class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;
class LLVMVFTableProvider;
class Resolver;

[[nodiscard]] LLVMBasedCallGraph
buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, CallGraphAnalysisType CGType,
llvm::ArrayRef<const llvm::Function *> EntryPoints,
LLVMTypeHierarchy &TH, LLVMVFTableProvider &VTP,
DIBasedTypeHierarchy &TH, LLVMVFTableProvider &VTP,
LLVMAliasInfoRef PT = nullptr,
Soundness S = Soundness::Soundy);

Expand All @@ -36,7 +36,7 @@ buildLLVMBasedCallGraph(const LLVMProjectIRDB &IRDB, Resolver &CGResolver,
[[nodiscard]] LLVMBasedCallGraph
buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, CallGraphAnalysisType CGType,
llvm::ArrayRef<std::string> EntryPoints,
LLVMTypeHierarchy &TH, LLVMVFTableProvider &VTP,
DIBasedTypeHierarchy &TH, LLVMVFTableProvider &VTP,
LLVMAliasInfoRef PT = nullptr,
Soundness S = Soundness::Soundy);

Expand Down
8 changes: 3 additions & 5 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
#include "llvm/IR/Value.h"
#include "llvm/Support/raw_ostream.h"

#include <memory>

namespace psr {
class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;
class LLVMProjectIRDB;
class Resolver;

Expand Down Expand Up @@ -73,7 +71,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
/// IRDB. True by default
explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB, CallGraphAnalysisType CGType,
llvm::ArrayRef<std::string> EntryPoints = {},
LLVMTypeHierarchy *TH = nullptr,
DIBasedTypeHierarchy *TH = nullptr,
LLVMAliasInfoRef PT = nullptr,
Soundness S = Soundness::Soundy,
bool IncludeGlobals = true);
Expand All @@ -93,7 +91,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
explicit LLVMBasedICFG(const LLVMProjectIRDB *IRDB,
const CallGraphData &SerializedCG);

// Deleter of LLVMTypeHierarchy may be unknown here...
// Deleter of DIBasedTypeHierarchy may be unknown here...
~LLVMBasedICFG();

LLVMBasedICFG(const LLVMBasedICFG &) = delete;
Expand Down
8 changes: 4 additions & 4 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace llvm {
class Module;
class StructType;
class DIType;
class GlobalVariable;
} // namespace llvm

Expand All @@ -28,12 +28,12 @@ class LLVMVFTableProvider {
explicit LLVMVFTableProvider(const llvm::Module &Mod);
explicit LLVMVFTableProvider(const LLVMProjectIRDB &IRDB);

[[nodiscard]] bool hasVFTable(const llvm::StructType *Type) const;
[[nodiscard]] bool hasVFTable(const llvm::DIType *Type) const;
[[nodiscard]] const LLVMVFTable *
getVFTableOrNull(const llvm::StructType *Type) const;
getVFTableOrNull(const llvm::DIType *Type) const;

private:
std::unordered_map<const llvm::StructType *, LLVMVFTable> TypeVFTMap;
std::unordered_map<const llvm::DIType *, LLVMVFTable> TypeVFTMap;
};
} // namespace psr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class CallBase;
} // namespace llvm

namespace psr {
class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;
class CHAResolver : public Resolver {
public:
CHAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP,
const LLVMTypeHierarchy *TH);
const DIBasedTypeHierarchy *TH);

// Deleting an incomplete type (LLVMTypeHierarchy) is UB, so instantiate the
// dtor in CHAResolver.cpp
Expand All @@ -45,7 +45,7 @@ class CHAResolver : public Resolver {
}

protected:
MaybeUniquePtr<const LLVMTypeHierarchy, true> TH;
MaybeUniquePtr<const DIBasedTypeHierarchy, true> TH;
};
} // namespace psr

Expand Down
15 changes: 9 additions & 6 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h"
#include "phasar/PhasarLLVM/Pointer/TypeGraphs/CachedTypeGraph.h"
#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"
// To switch the TypeGraph
// #include "phasar/PhasarLLVM/Pointer/TypeGraphs/LazyTypeGraph.h"

Expand All @@ -33,12 +34,13 @@ class BitCastInst;

namespace psr {

class DTAResolver : public CHAResolver {
class [[deprecated("Does not work with opaque pointers anymore")]] DTAResolver
: public CHAResolver {
public:
using TypeGraph_t = CachedTypeGraph;

DTAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP,
const LLVMTypeHierarchy *TH);
const DIBasedTypeHierarchy *TH);

~DTAResolver() override = default;

Expand All @@ -48,8 +50,8 @@ class DTAResolver : public CHAResolver {

[[nodiscard]] std::string str() const override;

[[nodiscard]] bool
mutatesHelperAnalysisInformation() const noexcept override {
[[nodiscard]] bool mutatesHelperAnalysisInformation()
const noexcept override {
return false;
}

Expand All @@ -60,13 +62,14 @@ class DTAResolver : public CHAResolver {
* An heuristic that return true if the bitcast instruction is interesting to
* take into the DTA relational graph
*/
static bool
heuristicAntiConstructorThisType(const llvm::BitCastInst *BitCast);
static bool heuristicAntiConstructorThisType(
const llvm::BitCastInst *BitCast);

/**
* Another heuristic that return true if the bitcast instruction is
* interesting to take into the DTA relational graph (use the presence or not
* of vtable)

*/
bool heuristicAntiConstructorVtablePos(const llvm::BitCastInst *BitCast);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Value;

namespace psr {

class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;

class OTFResolver : public Resolver {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace llvm {
class CallBase;
class StructType;
class DICompositeType;
} // namespace llvm

namespace psr {
class DIBasedTypeHierarchy;
class RTAResolver : public CHAResolver {
public:
RTAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP,
const LLVMTypeHierarchy *TH);
const DIBasedTypeHierarchy *TH);

~RTAResolver() override = default;

Expand All @@ -44,9 +45,9 @@ class RTAResolver : public CHAResolver {
}

private:
void resolveAllocatedStructTypes();
void resolveAllocatedCompositeTypes();

std::vector<const llvm::StructType *> AllocatedStructTypes;
std::vector<const llvm::DICompositeType *> AllocatedCompositeTypes;
};
} // namespace psr

Expand Down
15 changes: 8 additions & 7 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"

#include "llvm/ADT/DenseSet.h"
#include "llvm/IR/DerivedTypes.h"

#include <memory>
#include <optional>
Expand All @@ -29,30 +30,30 @@ namespace llvm {
class Instruction;
class CallBase;
class Function;
class StructType;
class DIType;
} // namespace llvm

namespace psr {
class LLVMProjectIRDB;
class LLVMVFTableProvider;
class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;
enum class CallGraphAnalysisType;

/// Assuming that `CallSite` is a virtual call through a vtable, retrieves the
/// index in the vtable of the virtual function called.
[[nodiscard]] std::optional<unsigned>
getVFTIndex(const llvm::CallBase *CallSite);

/// Assuming that `CallSite` is a vall to a non-static member function,
/// Assuming that `CallSite` is a call to a non-static member function,
/// retrieves the type of the receiver. Returns nullptr, if the receiver-type
/// could not be extracted
[[nodiscard]] const llvm::StructType *
[[nodiscard]] const llvm::DIType *
getReceiverType(const llvm::CallBase *CallSite);

/// Assuming that `CallSite` is a virtual call, where `Idx` is retrieved through
/// `getVFTIndex()` and `T` through `getReceiverType()`
[[nodiscard]] const llvm::Function *
getNonPureVirtualVFTEntry(const llvm::StructType *T, unsigned Idx,
getNonPureVirtualVFTEntry(const llvm::DIType *T, unsigned Idx,
const llvm::CallBase *CallSite,
const psr::LLVMVFTableProvider &VTP);

Expand All @@ -73,7 +74,7 @@ class Resolver {
const LLVMVFTableProvider *VTP;

const llvm::Function *
getNonPureVirtualVFTEntry(const llvm::StructType *T, unsigned Idx,
getNonPureVirtualVFTEntry(const llvm::DIType *T, unsigned Idx,
const llvm::CallBase *CallSite) {
if (!VTP) {
return nullptr;
Expand Down Expand Up @@ -115,7 +116,7 @@ class Resolver {
static std::unique_ptr<Resolver> create(CallGraphAnalysisType Ty,
const LLVMProjectIRDB *IRDB,
const LLVMVFTableProvider *VTP,
const LLVMTypeHierarchy *TH,
const DIBasedTypeHierarchy *TH,
LLVMAliasInfoRef PT = nullptr);
};
} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StructType;
namespace psr {

class LLVMBasedICFG;
class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;

class InterMonoFullConstantPropagation
: public IntraMonoFullConstantPropagation,
Expand All @@ -48,7 +48,7 @@ class InterMonoFullConstantPropagation
using mono_container_t = IntraMonoFullConstantPropagation::mono_container_t;

InterMonoFullConstantPropagation(const LLVMProjectIRDB *IRDB,
const LLVMTypeHierarchy *TH,
const DIBasedTypeHierarchy *TH,
const LLVMBasedICFG *ICF,
LLVMAliasInfoRef PT,
std::vector<std::string> EntryPoints = {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StructType;

namespace psr {

class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;

struct InterMonoSolverTestDomain : LLVMAnalysisDomainDefault {
using mono_container_t = BitVectorSet<LLVMAnalysisDomainDefault::d_t>;
Expand All @@ -52,8 +52,9 @@ class InterMonoSolverTest : public InterMonoProblem<InterMonoSolverTestDomain> {
using i_t = InterMonoSolverTestDomain::i_t;
using mono_container_t = InterMonoSolverTestDomain::mono_container_t;

InterMonoSolverTest(const LLVMProjectIRDB *IRDB, const LLVMTypeHierarchy *TH,
const LLVMBasedICFG *ICF, LLVMAliasInfoRef PT,
InterMonoSolverTest(const LLVMProjectIRDB *IRDB,
const DIBasedTypeHierarchy *TH, const LLVMBasedICFG *ICF,
LLVMAliasInfoRef PT,
std::vector<std::string> EntryPoints = {});

~InterMonoSolverTest() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StructType;

namespace psr {

class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;

struct InterMonoTaintAnalysisDomain : LLVMAnalysisDomainDefault {
using mono_container_t = BitVectorSet<LLVMAnalysisDomainDefault::d_t>;
Expand All @@ -56,8 +56,9 @@ class InterMonoTaintAnalysis
using ConfigurationTy = LLVMTaintConfig;

InterMonoTaintAnalysis(const LLVMProjectIRDB *IRDB,
const LLVMTypeHierarchy *TH, const LLVMBasedICFG *ICF,
LLVMAliasInfoRef PT, const LLVMTaintConfig &Config,
const DIBasedTypeHierarchy *TH,
const LLVMBasedICFG *ICF, LLVMAliasInfoRef PT,
const LLVMTaintConfig &Config,
std::vector<std::string> EntryPoints = {});

~InterMonoTaintAnalysis() override = default;
Expand Down
Loading
Loading