Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9179cf0
Analysis Printer (#17)
fabianbs96 Oct 17, 2023
ec0abf4
OnTheFlyReporting Initial Commit
SanthoshMohan97 Oct 31, 2023
3062f3d
Merge branch 'development' into development
fabianbs96 Nov 6, 2023
70e3241
Merge branch 'development' into development
fabianbs96 Nov 14, 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
b30ceee
onTheFlyAnalysis makeUniquePtr
SanthoshMohan97 Nov 24, 2023
a75309e
Merge branch 'development' into development
fabianbs96 Nov 25, 2023
e244eea
Merge branch 'secure-software-engineering:development' into development
fabianbs96 Nov 25, 2023
51e60a1
OnTheFlyReporting Initial Commit
SanthoshMohan97 Oct 31, 2023
07b57df
onTheFlyAnalysis makeUniquePtr
SanthoshMohan97 Nov 24, 2023
d44fe00
Merge branch 'f-onTheFlyReporting' of github.com:fabianbs96/phasar in…
SanthoshMohan97 Dec 2, 2023
af3757a
addressing minor error in prev commit
SanthoshMohan97 Dec 2, 2023
63c27c6
Refactoring Warn Variable and Refactoring lambda flow for AnalysisPri…
SanthoshMohan97 Dec 11, 2023
24f91da
Integrating sourceMgr to AnalysisPrinter
SanthoshMohan97 Dec 20, 2023
2d27f5e
Testcase for OnTheFlyAnalysisPrinting
SanthoshMohan97 Jan 3, 2024
b874c05
Testcase for SourceMgrPrinter
SanthoshMohan97 Jan 9, 2024
2a28822
MaybeUniquePtr for SourceMgrPrinter
SanthoshMohan97 Jan 9, 2024
52b6e21
Merge remote-tracking branch 'origin/development' into HEAD
sritejakv Jan 30, 2024
27c4c49
Merge remote-tracking branch 'mainline/development' into development
fabianbs96 Feb 2, 2024
8be9839
Merge branch 'development' into f-onTheFlyReporting
fabianbs96 Feb 2, 2024
0341768
Minor review comments
SanthoshMohan97 Feb 3, 2024
1369499
refactoring the printers
sritejakv Feb 6, 2024
29e7b8a
adding TODOs
sritejakv Feb 9, 2024
6741866
more TODOs
sritejakv Feb 9, 2024
1cc8a26
Refactor AnalysisPrinter part1
SanthoshMohan97 Feb 12, 2024
ca7565b
Refactor AnalysisPrinter part2
SanthoshMohan97 Feb 12, 2024
54af9e6
dev: update AnalysisPrinterBase, integrate and fix tests
sritejakv Feb 14, 2024
479646f
adding warning kind
sritejakv Feb 14, 2024
61afaa1
fix ci
sritejakv Feb 14, 2024
0ae5d1f
update codeowners for analysis-printer
sritejakv Feb 21, 2024
90e13ef
Refactor SourceManagerPrinter
fabianbs96 Feb 21, 2024
824490d
Minor in OTF Printer Test
fabianbs96 Feb 21, 2024
9a17c91
fixing review feedback
sritejakv Feb 21, 2024
b7539ec
fix l_t printing
sritejakv Feb 22, 2024
f8d46e9
Mandating analysisType to tyestate descriptions
sritejakv Feb 23, 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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Checks: '-*,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
-misc-use-anonymous-namespace,
readability-*,
-readability-function-cognitive-complexity,
-readability-else-after*,
Expand Down
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ Dockerfile @janniclas
/.docker/ @janniclas

/include/phasar/Utils/Logger.h @MMory
/include/phasar/Utils/AnalysisPrinterBase.h @sritejakv
/include/phasar/Utils/DefaultAnalysisPrinter.h @sritejakv
/include/phasar/Utils/NullAnalysisPrinter.h @sritejakv
/include/phasar/Utils/OnTheFlyAnalysisPrinter.h @sritejakv
/include/phasar/PhasarLLVM/Utils/SourceMgrPrinter.h @sritejakv
/lib/PhasarLLVM/Utils/SourceMgrPrinter.cpp @sritejakv
2 changes: 1 addition & 1 deletion include/phasar/DataFlow/IfdsIde/IDETabulationProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "phasar/DataFlow/IfdsIde/IFDSIDESolverConfig.h"
#include "phasar/DataFlow/IfdsIde/InitialSeeds.h"
#include "phasar/DataFlow/IfdsIde/SolverResults.h"
#include "phasar/PhasarLLVM/Utils/NullAnalysisPrinter.h"
#include "phasar/Utils/JoinLattice.h"
#include "phasar/Utils/NullAnalysisPrinter.h"
#include "phasar/Utils/Printer.h"
#include "phasar/Utils/Soundness.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMZeroValue.h"
#include "phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"
#include "phasar/Utils/ByRef.h"
#include "phasar/Utils/JoinLattice.h"
#include "phasar/Utils/Logger.h"
Expand Down Expand Up @@ -529,10 +530,9 @@ class IDETypeStateAnalysis
if (const auto *Alloca =
llvm::dyn_cast<llvm::AllocaInst>(Res.first)) {
if (Res.second == TSD->error()) {
Warning<IDETypeStateAnalysisDomain<TypeStateDescriptionTy>>
Warn(&I, Res.first, TSD->error());
// ERROR STATE DETECTED
this->Printer->onResult(Warn);
this->Printer->onResult(&I, Res.first, TSD->error(),
TSD->analysisType());
}
}
}
Expand All @@ -541,10 +541,9 @@ class IDETypeStateAnalysis
if (const auto *Alloca =
llvm::dyn_cast<llvm::AllocaInst>(Res.first)) {
if (Res.second == TSD->error()) {
Warning<IDETypeStateAnalysisDomain<TypeStateDescriptionTy>>
Warn(&I, Res.first, TSD->error());
// ERROR STATE DETECTED
this->Printer->onResult(Warn);
this->Printer->onResult(&I, Res.first, TSD->error(),
TSD->analysisType());
}
}
}
Expand All @@ -553,7 +552,7 @@ class IDETypeStateAnalysis
}
}

this->Printer->onFinalize(OS);
this->Printer->onFinalize();
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class CSTDFILEIOTypeStateDescription
[[nodiscard]] TypeStateDescription::State uninit() const override;
[[nodiscard]] TypeStateDescription::State start() const override;
[[nodiscard]] TypeStateDescription::State error() const override;
[[nodiscard]] DataFlowAnalysisType analysisType() const override;
};

extern template class IDETypeStateAnalysis<CSTDFILEIOTypeStateDescription>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class OpenSSLEVPKDFCTXDescription
[[nodiscard]] State uninit() const override;
[[nodiscard]] State start() const override;
[[nodiscard]] State error() const override;
[[nodiscard]] DataFlowAnalysisType analysisType() const override;
/*
/// Checks all callSites, where a EVP_KDF object needs to be in a
/// certain state, such that the state transition for EVP_KDF_CTX is valid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class OpenSSLEVPKDFDescription
[[nodiscard]] TypeStateDescription::State start() const override;

[[nodiscard]] TypeStateDescription::State error() const override;

[[nodiscard]] DataFlowAnalysisType analysisType() const override;
};

} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class OpenSSLSecureHeapDescription
[[nodiscard]] TypeStateDescription::State uninit() const override;
[[nodiscard]] TypeStateDescription::State start() const override;
[[nodiscard]] TypeStateDescription::State error() const override;
[[nodiscard]] DataFlowAnalysisType analysisType() const override;
};

} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class OpenSSLSecureMemoryDescription
[[nodiscard]] TypeStateDescription::State uninit() const override;
[[nodiscard]] TypeStateDescription::State start() const override;
[[nodiscard]] TypeStateDescription::State error() const override;
[[nodiscard]] DataFlowAnalysisType analysisType() const override;
};

} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_TYPESTATEDESCRIPTIONS_TYPESTATEDESCRIPTION_H
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_TYPESTATEDESCRIPTIONS_TYPESTATEDESCRIPTION_H

#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"

#include "llvm/IR/InstrTypes.h"

#include <set>
Expand All @@ -28,6 +30,7 @@ struct TypeStateDescriptionBase {
getConsumerParamIdx(llvm::StringRef F) const = 0;
[[nodiscard]] virtual std::set<int>
getFactoryParamIdx(llvm::StringRef F) const = 0;
[[nodiscard]] virtual DataFlowAnalysisType analysisType() const = 0;
};

/**
Expand Down
44 changes: 0 additions & 44 deletions include/phasar/PhasarLLVM/Utils/AnalysisPrinterBase.h

This file was deleted.

47 changes: 0 additions & 47 deletions include/phasar/PhasarLLVM/Utils/DefaultAnalysisPrinter.h

This file was deleted.

11 changes: 11 additions & 0 deletions include/phasar/PhasarLLVM/Utils/LLVMIRToSrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "nlohmann/json.hpp"

#include <optional>
#include <string>

// Forward declaration of types for which we only use its pointer or ref type
Expand All @@ -39,6 +40,7 @@ namespace psr {
[[nodiscard]] std::string getFunctionNameFromIR(const llvm::Value *V);

[[nodiscard]] std::string getFilePathFromIR(const llvm::Value *V);
[[nodiscard]] std::string getFilePathFromIR(const llvm::DIFile *DIF);

[[nodiscard]] std::string getDirectoryFromIR(const llvm::Value *V);

Expand Down Expand Up @@ -85,6 +87,15 @@ void to_json(nlohmann::json &J, const SourceCodeInfo &Info);

[[nodiscard]] SourceCodeInfo getSrcCodeInfoFromIR(const llvm::Value *V);

struct DebugLocation {
unsigned Line{};
unsigned Column{};
const llvm::DIFile *File{};
};

[[nodiscard]] std::optional<DebugLocation>
getDebugLocation(const llvm::Value *V);

} // namespace psr

#endif
36 changes: 36 additions & 0 deletions include/phasar/PhasarLLVM/Utils/LLVMSourceManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef PHASAR_PHASARLLVM_UTILS_LLVMSOURCEMANAGER_H
#define PHASAR_PHASARLLVM_UTILS_LLVMSOURCEMANAGER_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/SourceMgr.h"

#include <optional>

namespace llvm {
class Value;
class DIFile;
} // namespace llvm

namespace psr {
struct ManagedDebugLocation {
unsigned Line{};
unsigned Column{};
unsigned File{};
};

class LLVMSourceManager {
public:
[[nodiscard]] std::optional<ManagedDebugLocation>
getDebugLocation(const llvm::Value *V);

void print(llvm::raw_ostream &OS, ManagedDebugLocation Loc,
llvm::SourceMgr::DiagKind DiagKind, const llvm::Twine &Message);

private:
llvm::DenseMap<const llvm::DIFile *, unsigned> FileIdMap{};
llvm::SourceMgr SrcMgr{};
};
} // namespace psr

#endif // PHASAR_PHASARLLVM_UTILS_LLVMSOURCEMANAGER_H
71 changes: 71 additions & 0 deletions include/phasar/PhasarLLVM/Utils/SourceMgrPrinter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef PHASAR_PHASARLLVM_UTILS_SOURCEMGRPRINTER_H
#define PHASAR_PHASARLLVM_UTILS_SOURCEMGRPRINTER_H

#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"
#include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h"
#include "phasar/PhasarLLVM/Utils/LLVMSourceManager.h"
#include "phasar/Utils/AnalysisPrinterBase.h"
#include "phasar/Utils/MaybeUniquePtr.h"

#include "llvm/ADT/FunctionExtras.h"
#include "llvm/Support/raw_ostream.h"

#include <type_traits>

namespace psr {

namespace detail {
class SourceMgrPrinterBase {
public:
explicit SourceMgrPrinterBase(
llvm::unique_function<std::string(DataFlowAnalysisType)> &&PrintMessage,
llvm::raw_ostream &OS = llvm::errs(),
llvm::SourceMgr::DiagKind WKind = llvm::SourceMgr::DK_Warning);

explicit SourceMgrPrinterBase(
llvm::unique_function<std::string(DataFlowAnalysisType)> &&PrintMessage,
const llvm::Twine &OutFileName,
llvm::SourceMgr::DiagKind WKind = llvm::SourceMgr::DK_Warning);

protected:
LLVMSourceManager SrcMgr;

llvm::unique_function<std::string(DataFlowAnalysisType)> GetPrintMessage;
MaybeUniquePtr<llvm::raw_ostream> OS = &llvm::errs();
llvm::SourceMgr::DiagKind WarningKind;
};
} // namespace detail

template <typename AnalysisDomainTy>
class SourceMgrPrinter : public AnalysisPrinterBase<AnalysisDomainTy>,
private detail::SourceMgrPrinterBase {
using n_t = typename AnalysisDomainTy::n_t;
using d_t = typename AnalysisDomainTy::d_t;
using l_t = typename AnalysisDomainTy::l_t;

public:
explicit SourceMgrPrinter(
llvm::unique_function<std::string(DataFlowAnalysisType)> &&PrintMessage,
llvm::raw_ostream &OS = llvm::errs(),
llvm::SourceMgr::DiagKind WKind = llvm::SourceMgr::DK_Warning)
: detail::SourceMgrPrinterBase(std::move(PrintMessage), OS, WKind) {}

private:
void doOnResult(n_t Inst, d_t Fact, l_t /*Value*/,
DataFlowAnalysisType AnalysisType) override {
auto SrcLoc = SrcMgr.getDebugLocation(Inst);
if constexpr (std::is_convertible_v<d_t, const llvm::Value *>) {
if (!SrcLoc) {
SrcLoc =
SrcMgr.getDebugLocation(static_cast<const llvm::Value *>(Fact));
}
}

if (SrcLoc) {
SrcMgr.print(*OS, *SrcLoc, WarningKind, GetPrintMessage(AnalysisType));
}
}
};

} // namespace psr
#endif
Loading