Skip to content

Commit

Permalink
Merge branch 'development' into f-clang-15
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed Aug 9, 2024
2 parents b4783b9 + 6e0f6f6 commit 49707eb
Show file tree
Hide file tree
Showing 32 changed files with 211 additions and 251 deletions.
1 change: 1 addition & 0 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- 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)
- No VTable handling anymore -- has been out-sourced into `LLVMVFTableProvider`
Expand Down
1 change: 0 additions & 1 deletion Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ set(PHASAR_COMPONENTS
llvm
llvm_ifdside
analysis_strategy
controller
)

list(REMOVE_DUPLICATES phasar_FIND_COMPONENTS)
Expand Down
1 change: 0 additions & 1 deletion include/phasar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "phasar/AnalysisStrategy.h"
#include "phasar/Config.h"
#include "phasar/ControlFlow.h"
#include "phasar/Controller.h"
#include "phasar/DB.h"
#include "phasar/DataFlow.h"
#include "phasar/Domain.h"
Expand Down
16 changes: 0 additions & 16 deletions include/phasar/Controller.h

This file was deleted.

22 changes: 22 additions & 0 deletions include/phasar/Utils/InitPhasar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/******************************************************************************
* Copyright (c) 2024 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
*****************************************************************************/

#include "llvm/Support/InitLLVM.h"

namespace psr {
class InitPhasar : llvm::InitLLVM {
public:
InitPhasar(int &Argc, const char **&Argv) noexcept;
InitPhasar(int &Argc, char **&Argv) noexcept
: InitPhasar(Argc, (const char **&)Argv) {}
};
} // namespace psr

#define PSR_INITIALIZER(argc, argv) \
const ::psr::InitPhasar PsrInitializerVar((argc), (argv))
2 changes: 0 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_subdirectory(PhasarPass)
add_subdirectory(DB)
add_subdirectory(Config)
add_subdirectory(Utils)
add_subdirectory(Controller)
add_subdirectory(Pointer)
add_subdirectory(ControlFlow)
if(BUILD_PHASAR_CLANG)
Expand Down Expand Up @@ -36,7 +35,6 @@ set(PHASAR_LINK_LIBS
phasar_llvm
phasar_llvm_ifdside
phasar_analysis_strategy
phasar_controller
)
if(SQLite3_FOUND)
list(APPEND PHASAR_LINK_LIBS phasar_db)
Expand Down
27 changes: 0 additions & 27 deletions lib/Controller/CMakeLists.txt

This file was deleted.

45 changes: 45 additions & 0 deletions lib/Utils/InitPhasar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "phasar/Utils/InitPhasar.h"

#include "phasar/Utils/Logger.h"

#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/raw_ostream.h"

using namespace psr;

#define PSR_ISSUE_TRACKER_URL \
"https://github.com/secure-software-engineering/phasar/issues"

InitPhasar::InitPhasar(int &Argc, const char **&Argv) noexcept
: llvm::InitLLVM(Argc, Argv) {
static std::nullptr_t InitGlobals = [] {
// Replace LLVM's bug report URL with ours
llvm::setBugReportMsg("PLEASE create a bug report at " PSR_ISSUE_TRACKER_URL
" and include the crash backtrace.\n ");

// Install custom error handlers, such that fatal errors do not start with
// "LLVM ERROR"
auto FatalErrorHandler = [](void * /*HandlerData*/, const char *Reason,
bool /*GenCrashDiag*/) {
// Prevent recursion in case our error handler itself fails
llvm::remove_fatal_error_handler();
llvm::remove_bad_alloc_error_handler();

// Write the actual error message
Logger::addLinePrefix(llvm::errs(), SeverityLevel::CRITICAL,
std::nullopt);
llvm::errs() << Reason << '\n';
llvm::errs().flush();
};

// NOTE: Install the bad_alloc handler before the fatal_error handler due to
// a bug in LLVM
// https://github.com/llvm/llvm-project/issues/83040
llvm::install_bad_alloc_error_handler(FatalErrorHandler, nullptr);
llvm::install_fatal_error_handler(FatalErrorHandler, nullptr);
// llvm::install_out_of_memory_new_handler() is already done by InitLLVM
return nullptr;
}();
(void)InitGlobals;
}
32 changes: 4 additions & 28 deletions tools/phasar-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,14 @@ else()
)
endif()

# Warning! There is a another listing of libraries inside cmake/phasar_macros.cmake.
# If this list is altered the other one should be altered accordingly.
add_subdirectory(Controller)

target_link_libraries(phasar-cli
PRIVATE
phasar_config
phasar_controller
phasar_llvm_controlflow
phasar_llvm_utils
phasar_analysis_strategy
phasar_llvm_ifdside
phasar_utils
phasar_mono
phasar_llvm_db
phasar_passes
phasar_llvm_pointer
phasar_llvm
phasar_llvm_typehierarchy
phasar_taintconfig

phasar
${PHASAR_STD_FILESYSTEM}
)

if (NOT PHASAR_IN_TREE)
if(USE_LLVM_FAT_LIB)
llvm_config(phasar-cli USE_SHARED ${LLVM_LINK_COMPONENTS})
else()
llvm_config(phasar-cli ${LLVM_LINK_COMPONENTS})
endif()

install(TARGETS phasar-cli
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(TARGETS phasar-cli)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Philipp Schubert and others
*****************************************************************************/

#include "phasar/Controller/AnalysisController.h"
#include "AnalysisController.h"

#include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h"
#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"
Expand All @@ -17,9 +17,8 @@

namespace psr {

static void
emitRequestedHelperAnalysisResults(AnalysisController::ControllerData &Data) {
auto WithResultFileOrStdout = [&ResultDirectory = Data.ResultDirectory](
void AnalysisController::emitRequestedHelperAnalysisResults() {
auto WithResultFileOrStdout = [&ResultDirectory = this->ResultDirectory](
const auto &FileName, auto Callback) {
if (!ResultDirectory.empty()) {
if (auto OFS = openFileStream(ResultDirectory.string() + FileName)) {
Expand All @@ -30,8 +29,8 @@ emitRequestedHelperAnalysisResults(AnalysisController::ControllerData &Data) {
}
};

auto EmitterOptions = Data.EmitterOptions;
auto &HA = *Data.HA;
auto EmitterOptions = this->EmitterOptions;
auto &HA = *this->HA;

if (EmitterOptions & AnalysisControllerEmitterOptions::EmitIR) {
WithResultFileOrStdout("/psr-preprocess-ir.ll", [&HA](auto &OS) {
Expand Down Expand Up @@ -96,24 +95,24 @@ emitRequestedHelperAnalysisResults(AnalysisController::ControllerData &Data) {
}
}

static void executeDemandDriven(AnalysisController::ControllerData & /*Data*/) {
static void executeDemandDriven(AnalysisController & /*Data*/) {
llvm::report_fatal_error(
"AnalysisStrategy 'demand-driven' not supported, yet!");
}
static void executeIncremental(AnalysisController::ControllerData & /*Data*/) {
static void executeIncremental(AnalysisController & /*Data*/) {
llvm::report_fatal_error(
"AnalysisStrategy 'incremental' not supported, yet!");
}
static void executeModuleWise(AnalysisController::ControllerData & /*Data*/) {
static void executeModuleWise(AnalysisController & /*Data*/) {
llvm::report_fatal_error(
"AnalysisStrategy 'module-wise' not supported, yet!");
}
static void executeVariational(AnalysisController::ControllerData & /*Data*/) {
static void executeVariational(AnalysisController & /*Data*/) {
llvm::report_fatal_error(
"AnalysisStrategy 'variational' not supported, yet!");
}

static void executeWholeProgram(AnalysisController::ControllerData &Data) {
static void executeWholeProgram(AnalysisController &Data) {
for (auto DataFlowAnalysis : Data.DataFlowAnalyses) {
using namespace controller;
switch (DataFlowAnalysis) {
Expand Down Expand Up @@ -171,60 +170,31 @@ static void executeWholeProgram(AnalysisController::ControllerData &Data) {
}
}

static void executeAs(AnalysisController::ControllerData &Data,
AnalysisStrategy Strategy) {
void AnalysisController::run() {
switch (Strategy) {
case AnalysisStrategy::None:
return;
case AnalysisStrategy::DemandDriven:
executeDemandDriven(Data);
executeDemandDriven(*this);
return;
case AnalysisStrategy::Incremental:
executeIncremental(Data);
executeIncremental(*this);
return;
case AnalysisStrategy::ModuleWise:
executeModuleWise(Data);
executeModuleWise(*this);
return;
case AnalysisStrategy::Variational:
executeVariational(Data);
executeVariational(*this);
return;
case AnalysisStrategy::WholeProgram:
executeWholeProgram(Data);
executeWholeProgram(*this);
return;
}
llvm_unreachable(
"All AnalysisStrategy variants should be handled in the switch above!");
}

AnalysisController::AnalysisController(
HelperAnalyses &HA, std::vector<DataFlowAnalysisType> DataFlowAnalyses,
std::vector<std::string> AnalysisConfigs,
std::vector<std::string> EntryPoints, AnalysisStrategy Strategy,
AnalysisControllerEmitterOptions EmitterOptions,
IFDSIDESolverConfig SolverConfig, std::string ProjectID,
std::string OutDirectory)
: Data{
&HA,
std::move(DataFlowAnalyses),
std::move(AnalysisConfigs),
std::move(EntryPoints),
Strategy,
EmitterOptions,
std::move(ProjectID),
std::move(OutDirectory),
SolverConfig,
} {
if (!Data.ResultDirectory.empty()) {
// create directory for results
Data.ResultDirectory /= Data.ProjectID + "-" + createTimeStamp();
std::filesystem::create_directory(Data.ResultDirectory);
}
emitRequestedHelperAnalysisResults(Data);
executeAs(Data, Strategy);
}

LLVMTaintConfig
controller::makeTaintConfig(AnalysisController::ControllerData &Data) {
LLVMTaintConfig controller::makeTaintConfig(AnalysisController &Data) {
std::string AnalysisConfigPath =
!Data.AnalysisConfigs.empty() ? Data.AnalysisConfigs[0] : "";
return !AnalysisConfigPath.empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,26 @@
#define PHASAR_CONTROLLER_ANALYSISCONTROLLER_H

#include "phasar/AnalysisStrategy/Strategies.h"
#include "phasar/Controller/AnalysisControllerEmitterOptions.h"
#include "phasar/DataFlow/IfdsIde/IFDSIDESolverConfig.h"
#include "phasar/PhasarLLVM/HelperAnalyses.h"
#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"

#include "AnalysisControllerEmitterOptions.h"

#include <filesystem>
namespace psr {

class AnalysisController {
public:
struct ControllerData {
HelperAnalyses *HA{};
std::vector<DataFlowAnalysisType> DataFlowAnalyses;
std::vector<std::string> AnalysisConfigs;
std::vector<std::string> EntryPoints;
[[maybe_unused]] AnalysisStrategy Strategy;
AnalysisControllerEmitterOptions EmitterOptions =
AnalysisControllerEmitterOptions::None;
std::string ProjectID;
std::filesystem::path ResultDirectory;
IFDSIDESolverConfig SolverConfig{};
};

explicit AnalysisController(
HelperAnalyses &HA, std::vector<DataFlowAnalysisType> DataFlowAnalyses,
std::vector<std::string> AnalysisConfigs,
std::vector<std::string> EntryPoints, AnalysisStrategy Strategy,
AnalysisControllerEmitterOptions EmitterOptions,
IFDSIDESolverConfig SolverConfig,
std::string ProjectID = "default-phasar-project",
std::string OutDirectory = "");
struct AnalysisController {
HelperAnalyses *HA{};
std::vector<DataFlowAnalysisType> DataFlowAnalyses;
std::vector<std::string> AnalysisConfigs;
std::vector<std::string> EntryPoints;
[[maybe_unused]] AnalysisStrategy Strategy{};
AnalysisControllerEmitterOptions EmitterOptions =
AnalysisControllerEmitterOptions::None;
IFDSIDESolverConfig SolverConfig{};
std::string ProjectID = "default-phasar-project";
std::filesystem::path ResultDirectory;

static constexpr bool
needsToEmitPTA(AnalysisControllerEmitterOptions EmitterOptions) {
Expand All @@ -50,8 +39,8 @@ class AnalysisController {
(EmitterOptions & AnalysisControllerEmitterOptions::EmitPTAAsText);
}

private:
ControllerData Data;
void emitRequestedHelperAnalysisResults();
void run();
};

} // namespace psr
Expand Down
Loading

0 comments on commit 49707eb

Please sign in to comment.