-
Notifications
You must be signed in to change notification settings - Fork 148
SVF Pointer Analyses #767
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
fabianbs96
merged 22 commits into
secure-software-engineering:development
from
fabianbs96:f-PhasarSVF
May 19, 2025
Merged
SVF Pointer Analyses #767
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8914e0e
Add SVF dependency + make the LLVMBasedAliasAnalysis polymorphic to a…
fabianbs96 3a37d48
Add public interface for SVFPointsToSet
fabianbs96 3a227df
Add SVFPointsToInfo + Fix PointsToInfoBase
fabianbs96 2fe2ec8
Fixes in PointsToInfo + add minimal tests
fabianbs96 d309744
Add CRTPBase utility
fabianbs96 fb2118c
New test + some cleanup
fabianbs96 b8f297b
Merge branch 'development' into f-PhasarSVF
fabianbs96 6bc1988
Fix build due to merge
fabianbs96 f21feb1
Merge branch 'development' into f-PhasarSVF
fabianbs96 dcef1a1
minor
fabianbs96 cc500ce
Simplify the SVF alias analyses + make FunctionAliasView more type-safe
fabianbs96 72b894f
minor
fabianbs96 6fe1312
Merge branch 'development' into f-PhasarSVF
fabianbs96 5c4f52b
Regain precision
fabianbs96 c782f0b
Get rid of UB + aim to resolve memory leaks with SVF
fabianbs96 ba75085
Merge branch 'development' into f-PhasarSVF
fabianbs96 a1250ca
Merge branch 'development' into f-PhasarSVF
fabianbs96 2bb1072
Fix SVF memory leak
fabianbs96 37bcaca
pre-commit with new clang-format version
fabianbs96 de0539d
Apply review comments
fabianbs96 dc89459
Getting rid of the PSR_BIND_ALIASVIEW macro
fabianbs96 1698ac7
fix compilation
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -13,4 +13,6 @@ | |
|
||
#cmakedefine PHASAR_HAS_SQLITE | ||
|
||
#cmakedefine PHASAR_USE_SVF | ||
|
||
#endif /* PHASAR_CONFIG_CONFIG_H */ |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,99 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2025 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_POINTER_ALIASANALYSISVIEW_H | ||
#define PHASAR_PHASARLLVM_POINTER_ALIASANALYSISVIEW_H | ||
|
||
#include "phasar/Pointer/AliasAnalysisType.h" | ||
#include "phasar/Pointer/AliasResult.h" | ||
|
||
#include <memory> | ||
#include <type_traits> | ||
|
||
namespace llvm { | ||
class Value; | ||
class DataLayout; | ||
class Function; | ||
} // namespace llvm | ||
|
||
namespace psr { | ||
class LLVMProjectIRDB; | ||
|
||
class FunctionAliasView { | ||
public: | ||
template <typename T> | ||
using AliasCallbackTy = AliasResult (*)(T *, const llvm::Value *, | ||
const llvm::Value *, | ||
const llvm::DataLayout &); | ||
|
||
[[nodiscard]] AliasResult alias(const llvm::Value *V, const llvm::Value *Rep, | ||
const llvm::DataLayout &DL) { | ||
return Alias(Context, V, Rep, DL); | ||
} | ||
|
||
template < | ||
typename T, typename AliasFn, | ||
typename = std::enable_if_t<std::is_empty_v<AliasFn> && | ||
std::is_default_constructible_v<AliasFn>>> | ||
constexpr FunctionAliasView(T *Context, AliasFn /*Alias*/) noexcept | ||
: Context(Context), Alias(&callAlias<T, AliasFn>) {} | ||
|
||
private: | ||
template <typename T, typename AliasFn> | ||
static AliasResult callAlias(void *Context, const llvm::Value *V1, | ||
const llvm::Value *V2, | ||
const llvm::DataLayout &DL) { | ||
return AliasFn{}(static_cast<T *>(Context), V1, V2, DL); | ||
} | ||
|
||
void *Context{}; | ||
AliasCallbackTy<void> Alias{}; | ||
}; | ||
|
||
class AliasAnalysisView { | ||
public: | ||
constexpr AliasAnalysisView(AliasAnalysisType PATy) noexcept : PATy(PATy) {} | ||
|
||
virtual ~AliasAnalysisView() = default; | ||
|
||
[[nodiscard]] FunctionAliasView getAAResults(const llvm::Function *F) { | ||
assert(F != nullptr); | ||
return doGetAAResults(F); | ||
} | ||
|
||
void erase(llvm::Function *F) noexcept { | ||
assert(F != nullptr); | ||
doErase(F); | ||
} | ||
|
||
void clear() noexcept { doClear(); } | ||
|
||
[[nodiscard]] constexpr AliasAnalysisType | ||
getPointerAnalysisType() const noexcept { | ||
return PATy; | ||
}; | ||
|
||
[[nodiscard]] static std::unique_ptr<AliasAnalysisView> | ||
create(LLVMProjectIRDB &IRDB, bool UseLazyEvaluation, AliasAnalysisType PATy); | ||
|
||
private: | ||
static std::unique_ptr<AliasAnalysisView> | ||
createLLVMBasedAnalysis(LLVMProjectIRDB &IRDB, bool UseLazyEvaluation, | ||
AliasAnalysisType PATy); | ||
|
||
virtual FunctionAliasView doGetAAResults(const llvm::Function *F) = 0; | ||
virtual void doErase(llvm::Function *F) noexcept = 0; | ||
virtual void doClear() noexcept = 0; | ||
|
||
AliasAnalysisType PATy{}; | ||
}; | ||
|
||
} // namespace psr | ||
|
||
#endif // PHASAR_PHASARLLVM_POINTER_ALIASANALYSISVIEW_H |
This file contains hidden or 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 hidden or 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,55 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2025 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_POINTER_SVF_SVFPOINTSTOSET_H | ||
#define PHASAR_PHASARLLVM_POINTER_SVF_SVFPOINTSTOSET_H | ||
|
||
#include "phasar/Config/phasar-config.h" | ||
#include "phasar/Pointer/PointsToInfo.h" | ||
|
||
#include "llvm/ADT/DenseSet.h" | ||
#include "llvm/IR/Value.h" | ||
|
||
#ifndef PHASAR_USE_SVF | ||
#error \ | ||
"Don't include SVFPointsToSet.h when PhASAR is not configured to include SVF. Set the cmake variable PHASAR_USE_SVF and retry." | ||
#endif | ||
|
||
namespace psr { | ||
class LLVMProjectIRDB; | ||
class SVFPointsToInfo; | ||
|
||
struct SVFPointsToInfoTraits { | ||
using v_t = const llvm::Value *; | ||
using n_t = const llvm::Instruction *; | ||
using o_t = uint32_t; | ||
|
||
// TODO: Use a more efficient representation; maybe even one that does not | ||
// require an expensive transformation from SVF::PointsTo | ||
using PointsToSetTy = llvm::SmallDenseSet<o_t>; | ||
|
||
// No special pointer type | ||
using PointsToSetPtrTy = PointsToSetTy; | ||
}; | ||
|
||
using SVFBasedPointsToInfo = PointsToInfo<SVFPointsToInfoTraits>; | ||
using SVFBasedPointsToInfoRef = PointsToInfoRef<SVFPointsToInfoTraits>; | ||
|
||
/// Use SVF to perform a VersionedFlowSensitive pointer analysis and return the | ||
/// results compatible to psr::PointsToInfo and psr::PointsToInfoRef | ||
[[nodiscard]] SVFBasedPointsToInfo | ||
createSVFVFSPointsToInfo(LLVMProjectIRDB &IRDB); | ||
|
||
/// Use SVF to perform a ContextDDA pointer analysis and return the | ||
/// results compatible to psr::PointsToInfo and psr::PointsToInfoRef | ||
[[nodiscard]] SVFBasedPointsToInfo | ||
createSVFDDAPointsToInfo(LLVMProjectIRDB &IRDB); | ||
|
||
} // namespace psr | ||
|
||
#endif // PHASAR_PHASARLLVM_POINTER_SVF_SVFPOINTSTOSET_H |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.