Skip to content

Commit

Permalink
Merge branch 'development' into f-FilteredAliasSet
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 authored May 10, 2024
2 parents 51a17e0 + 488da6a commit 51ed40e
Show file tree
Hide file tree
Showing 36 changed files with 168 additions and 122 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,12 @@ else()
endif()

# SQL
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
find_library(SQLITE3_LIBRARY NAMES sqlite3)
find_package(SQLite3)
if(SQLite3_FOUND)
set(PHASAR_HAS_SQLITE ON)
else()
set(PHASAR_HAS_SQLITE OFF)
endif()

option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM libraries if possible (default is OFF; always on if BUILD_SHARED_LIBS is ON)" OFF)

Expand Down
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ set -- "${POSITIONAL[@]}" # restore positional parameters

echo "installing phasar dependencies..."
if [ -x "$(command -v pacman)" ]; then
yes | sudo pacman -Syu --needed which zlib sqlite3 python3 doxygen gcc python-pip ninja cmake
yes | sudo pacman -Syu --needed which zlib python3 doxygen gcc ninja cmake
else
./utils/InstallAptDependencies.sh
fi
Expand Down
9 changes: 8 additions & 1 deletion cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function(generate_ll_file)
set(GEN_C_FLAGS -fno-discard-value-names -emit-llvm -S -w)
set(GEN_CMD_COMMENT "[LL]")

if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
list(APPEND GEN_CXX_FLAGS -Xclang -no-opaque-pointers)
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
list(APPEND GEN_C_FLAGS -Xclang -no-opaque-pointers)
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 @@ -121,7 +128,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 ${test_code_ll_file} -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}
COMMENT ${GEN_CMD_COMMENT}
DEPENDS ${GEN_LL_FILE}
VERBATIM
Expand Down
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
#cmakedefine DYNAMIC_LOG
#cmakedefine BUILD_PHASAR_CLANG

#cmakedefine PHASAR_HAS_SQLITE

#endif /* PHASAR_CONFIG_CONFIG_H */
6 changes: 5 additions & 1 deletion include/phasar/DB.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
#ifndef PHASAR_DB_H
#define PHASAR_DB_H

#include "phasar/DB/Hexastore.h"
#include "phasar/Config/phasar-config.h"
#include "phasar/DB/ProjectIRDBBase.h"

#ifdef PHASAR_HAS_SQLITE
#include "phasar/DB/Hexastore.h"
#include "phasar/DB/Queries.h"
#endif

#endif // PHASAR_DB_H
12 changes: 8 additions & 4 deletions include/phasar/DB/Hexastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
#ifndef PHASAR_DB_HEXASTORE_H_
#define PHASAR_DB_HEXASTORE_H_

#include "phasar/DB/Queries.h"
#include "phasar/Config/phasar-config.h"
#ifndef PHASAR_HAS_SQLITE
#error \
"Hexastore requires SQLite3. Please install libsqlite3-dev and reconfigure PhASAR."
#endif

#include "llvm/Support/raw_ostream.h"

#include "boost/format.hpp"
#include "sqlite3.h"

#include <array>
#include <string>
#include <vector>

struct sqlite3;

namespace psr {
/**
* @brief Holds the results of a query to the Hexastore.
Expand Down Expand Up @@ -51,6 +54,7 @@ struct HSResult {
LHS.Object == RHS.Object;
}
};

/**
* A Hexastore is an efficient approach to store large graphs.
* This approach is based on the paper "Database-Backed Program Analysis
Expand Down
15 changes: 2 additions & 13 deletions include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

namespace psr {

Expand Down Expand Up @@ -368,18 +367,8 @@ template <typename AnalysisDomainTy, unsigned K> class InterMonoSolver {
}
// Compute the data-flow facts using the respective kind of flows
if (ICF->isCallSite(Src)) {
// Handle call flow(s)
if (!isIntraEdge(Edge)) {
// real call
for (auto &[Ctx, Facts] : Analysis[Src]) {
processCall(Edge); // TODO: decompose into processCall and
// processCallToRet
}
} else {
// call-to-return
processCall(
Edge); // TODO: decompose into processCall and processCallToRet
}
// Handle call flow(s) and call-to-return flow
processCall(Edge);
} else if (ICF->isExitInst(Src)) {
// Handle return flow
processExit(Edge);
Expand Down
10 changes: 10 additions & 0 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
namespace psr {
class LLVMTypeHierarchy;
class LLVMProjectIRDB;
class Resolver;

class LLVMBasedICFG;
template <> struct CFGTraits<LLVMBasedICFG> : CFGTraits<LLVMBasedCFG> {};
Expand Down Expand Up @@ -87,6 +88,11 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
LLVMAliasInfoRef PT = nullptr,
Soundness S = Soundness::Soundy,
bool IncludeGlobals = true);
explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB, Resolver &CGResolver,
llvm::ArrayRef<std::string> EntryPoints = {},
LLVMTypeHierarchy *TH = nullptr,
Soundness S = Soundness::Soundy,
bool IncludeGlobals = true);

/// Creates an ICFG with an already given call-graph
explicit LLVMBasedICFG(CallGraph<n_t, f_t> CG, LLVMProjectIRDB *IRDB,
Expand Down Expand Up @@ -157,6 +163,10 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
[[nodiscard]] llvm::Function *buildCRuntimeGlobalCtorsDtorsModel(
llvm::Module &M, llvm::ArrayRef<llvm::Function *> UserEntryPoints);

void initialize(LLVMProjectIRDB *IRDB, Resolver &CGResolver,
llvm::ArrayRef<std::string> EntryPoints,
LLVMTypeHierarchy *TH, Soundness S, bool IncludeGlobals);

// ---

CallGraph<const llvm::Instruction *, const llvm::Function *> CG;
Expand Down
4 changes: 1 addition & 3 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ class Value;

namespace psr {

class LLVMBasedICFG;
class LLVMTypeHierarchy;

class OTFResolver : public Resolver {
protected:
LLVMBasedICFG &ICF;
LLVMAliasInfoRef PT;

public:
OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH, LLVMBasedICFG &ICF,
OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH,
LLVMAliasInfoRef PT);

~OTFResolver() override = default;
Expand Down
8 changes: 4 additions & 4 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace psr {
class LLVMProjectIRDB;
class LLVMTypeHierarchy;
enum class CallGraphAnalysisType;
class LLVMBasedICFG;
class LLVMPointsToInfo;

[[nodiscard]] std::optional<unsigned>
Expand Down Expand Up @@ -83,9 +82,10 @@ class Resolver {

[[nodiscard]] virtual std::string str() const = 0;

static std::unique_ptr<Resolver>
create(CallGraphAnalysisType Ty, LLVMProjectIRDB *IRDB, LLVMTypeHierarchy *TH,
LLVMBasedICFG *ICF = nullptr, LLVMAliasInfoRef PT = nullptr);
static std::unique_ptr<Resolver> create(CallGraphAnalysisType Ty,
LLVMProjectIRDB *IRDB,
LLVMTypeHierarchy *TH,
LLVMAliasInfoRef PT = nullptr);
};
} // namespace psr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H

#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constant.h"
Expand Down
1 change: 0 additions & 1 deletion lib/AnalysisStrategy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ file(GLOB_RECURSE ANALYSIS_STRATEGY_SRC *.h *.cpp)

add_phasar_library(phasar_analysis_strategy
${ANALYSIS_STRATEGY_SRC}
LINKS phasar_db phasar_controlflow
LLVM_LINK_COMPONENTS Support
)
44 changes: 25 additions & 19 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,35 @@ if(PHASAR_BUILD_DYNLIB)
set(PHASAR_DYNLIB_KIND SHARED)
endif()

set(PHASAR_LINK_LIBS
phasar_utils
phasar_passes
phasar_config
phasar_pointer
phasar_controlflow

phasar_llvm_utils
phasar_llvm_db
phasar_llvm_pointer
phasar_llvm_typehierarchy
phasar_llvm_controlflow

phasar_taintconfig
phasar_mono
phasar_llvm
phasar_llvm_ifdside
phasar_analysis_strategy
phasar_controller
)
if(SQLite3_FOUND)
list(APPEND PHASAR_LINK_LIBS phasar_db)
endif()

add_phasar_library(phasar ${PHASAR_DYNLIB_KIND}
FILES
LibPhasar.cpp
LINKS
phasar_utils
phasar_passes
phasar_config
phasar_db
phasar_pointer
phasar_controlflow

phasar_llvm_utils
phasar_llvm_db
phasar_llvm_pointer
phasar_llvm_typehierarchy
phasar_llvm_controlflow

phasar_taintconfig
phasar_mono
phasar_llvm
phasar_llvm_ifdside
phasar_analysis_strategy
phasar_controller
${PHASAR_LINK_LIBS}
LINK_PRIVATE
${Boost_LIBRARIES}
LLVM_LINK_COMPONENTS
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_phasar_library(phasar_controller
phasar_utils
phasar_analysis_strategy
phasar_taintconfig
phasar_passes

LLVM_LINK_COMPONENTS
Core
Expand Down
20 changes: 9 additions & 11 deletions lib/DB/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
file(GLOB_RECURSE DB_SRC *.h *.cpp)
if(SQLite3_FOUND)
file(GLOB_RECURSE DB_SRC *.h *.cpp)

add_phasar_library(phasar_db
${DB_SRC}
LINKS phasar_passes phasar_utils
LLVM_LINK_COMPONENTS Support
LINK_PRIVATE ${SQLITE3_LIBRARY}
)

target_include_directories(phasar_db
PRIVATE ${SQLITE3_INCLUDE_DIR}
)
add_phasar_library(phasar_db
${DB_SRC}
LINKS phasar_passes phasar_utils
LLVM_LINK_COMPONENTS Support
LINK_PRIVATE SQLite::SQLite3
)
endif()
7 changes: 6 additions & 1 deletion lib/DB/Hexastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@

#include "phasar/DB/Hexastore.h"

#include "phasar/DB/Queries.h"

#include "boost/format.hpp"
#include "sqlite3.h"

namespace psr {

Hexastore::Hexastore(const std::string &Filename) {
sqlite3_open(Filename.c_str(), &HSInternalDB);
const std::string Query = INIT;
const std::string &Query = INIT;
char *Err;
sqlite3_exec(HSInternalDB, Query.c_str(), callback, nullptr, &Err);
if (Err != nullptr) {
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/ControlFlow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_phasar_library(phasar_llvm_controlflow
phasar_llvm_pointer
phasar_llvm_typehierarchy
phasar_llvm_utils
phasar_db
phasar_controlflow

LLVM_LINK_COMPONENTS
Expand Down
Loading

0 comments on commit 51ed40e

Please sign in to comment.