Skip to content

Commit

Permalink
Merge OpaquePointersIntegration #730
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed Oct 7, 2024
2 parents 2c04104 + 3848eef commit a9cd897
Show file tree
Hide file tree
Showing 97 changed files with 1,100 additions and 991 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: true
matrix:
compiler: [ [clang++-14, clang-14] ]
compiler: [ [clang++-15, clang-15] ]
build: [ Debug, Release, DebugLibdeps ]
include:
- build: Debug
Expand Down Expand Up @@ -42,18 +42,18 @@ jobs:
- name: Install Strategy Dependencies
shell: bash
run: |
sudo apt-key adv --fetch-keys https://apt.llvm.org/llvm-snapshot.gpg.key
sudo add-apt-repository -y 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main'
sudo apt-get update
sudo apt-key adv --fetch-keys https://apt.llvm.org/llvm-snapshot.gpg.key && \
sudo add-apt-repository -y 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main' && \
sudo apt-get update && \
sudo apt-get -y install --no-install-recommends \
${{ matrix.compiler[1] }} \
llvm-14-dev \
libllvm14 \
libclang-common-14-dev \
libclang-14-dev \
libclang-cpp14-dev \
clang-tidy-14 \
libclang-rt-14-dev
clang-15 \
llvm-15-dev \
libllvm15 \
libclang-common-15-dev \
libclang-15-dev \
libclang-cpp15-dev \
clang-tidy-15 \
libclang-rt-15-dev
- uses: swift-actions/setup-swift@v2
with:
Expand Down
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
24 changes: 12 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM ubuntu:22.04
ARG LLVM_INSTALL_DIR="/usr/local/llvm-14"
ARG LLVM_INSTALL_DIR="/usr/local/llvm-15"
LABEL Name=phasar Version=2403

RUN apt -y update && apt install bash sudo -y
Expand All @@ -24,17 +24,17 @@ RUN apt-get update && \
apt-get install -y software-properties-common

RUN apt-key adv --fetch-keys https://apt.llvm.org/llvm-snapshot.gpg.key && \
add-apt-repository -y 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' && \
add-apt-repository -y 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main' && \
apt-get update && \
apt-get -y install --no-install-recommends \
clang-14 \
llvm-14-dev \
libllvm14 \
libclang-common-14-dev \
libclang-14-dev \
libclang-cpp14-dev \
clang-tidy-14 \
libclang-rt-14-dev
clang-15 \
llvm-15-dev \
libllvm15 \
libclang-common-15-dev \
libclang-15-dev \
libclang-cpp15-dev \
clang-tidy-15 \
libclang-rt-15-dev

RUN pip3 install Pygments pyyaml

Expand All @@ -43,8 +43,8 @@ RUN pip3 install Pygments pyyaml
# installing wllvm
RUN pip3 install wllvm

ENV CC=/usr/bin/clang-14
ENV CXX=/usr/bin/clang++-14
ENV CC=/usr/bin/clang-15
ENV CXX=/usr/bin/clang++-15

COPY . /usr/src/phasar

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
9 changes: 1 addition & 8 deletions cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ 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 @@ -139,7 +132,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_TOOL} -mem2reg -S -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file}
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} ${OPT_TOOL} -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 @@ -117,7 +117,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
10 changes: 3 additions & 7 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@
#include "llvm/IR/Value.h"
#include "llvm/Support/raw_ostream.h"

#include "nlohmann/json.hpp"

#include <memory>

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

Expand Down Expand Up @@ -82,7 +78,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 @@ -109,7 +105,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
: LLVMBasedICFG(static_cast<const LLVMProjectIRDB *>(IRDB),
SerializedCG) {}

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

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

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

Expand All @@ -30,19 +30,19 @@ 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;

[[nodiscard]] const llvm::GlobalVariable *
getVFTableGlobal(const llvm::StructType *Type) const;
getVFTableGlobal(const llvm::DIType *Type) const;

[[nodiscard]] const llvm::GlobalVariable *
getVFTableGlobal(const std::string &ClearTypeName) const;
getVFTableGlobal(llvm::StringRef ClearTypeName) const;

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

Expand Down
6 changes: 3 additions & 3 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class Function;
} // 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 @@ -43,7 +43,7 @@ class CHAResolver : public Resolver {
[[nodiscard]] std::string str() const override;

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

Expand Down
11 changes: 7 additions & 4 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,7 +34,8 @@ 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;

Expand All @@ -44,19 +46,20 @@ 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);

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

~DTAResolver() override = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Value;

namespace psr {

class LLVMTypeHierarchy;
class DIBasedTypeHierarchy;

class OTFResolver : public Resolver {
protected:
Expand Down
8 changes: 5 additions & 3 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ class CallBase;
class StructType;
class Function;
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 @@ -43,9 +45,9 @@ class RTAResolver : public CHAResolver {
[[nodiscard]] std::string str() const override;

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

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

Expand Down
11 changes: 6 additions & 5 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,19 +30,19 @@ 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;

[[nodiscard]] std::optional<unsigned>
getVFTIndex(const llvm::CallBase *CallSite);

[[nodiscard]] const llvm::StructType *
[[nodiscard]] const llvm::DIType *
getReceiverType(const llvm::CallBase *CallSite);

[[nodiscard]] std::string getReceiverTypeName(const llvm::CallBase *CallSite);
Expand All @@ -57,7 +58,7 @@ class Resolver {
Resolver(const LLVMProjectIRDB *IRDB);

const llvm::Function *
getNonPureVirtualVFTEntry(const llvm::StructType *T, unsigned Idx,
getNonPureVirtualVFTEntry(const llvm::DIType *T, unsigned Idx,
const llvm::CallBase *CallSite);

public:
Expand Down Expand Up @@ -91,7 +92,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
Loading

0 comments on commit a9cd897

Please sign in to comment.