Skip to content
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

Opaque Pointers Integration #730

Open
wants to merge 43 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d2c7bcb
replaced llvm-14 with llvm-15 in relevant files
mxHuber May 15, 2024
ab3fa86
annotation fix + test fix
mxHuber May 29, 2024
f703041
removed bitcasts and fixed tests
mxHuber Jun 3, 2024
b78d077
Fix Annotation.cpp + TaintConfigTest
fabianbs96 Jun 4, 2024
09e34aa
Quick-fix LLVMTypeHierarchyTest
fabianbs96 Jun 4, 2024
147ecd1
fix one IIA test
fabianbs96 Jun 4, 2024
fda53ef
Fix StringtestCpp for generalized LCA
fabianbs96 Jun 4, 2024
9b449d1
first half of tests fixed
mxHuber Jun 5, 2024
6b12b7b
fixed first half of tests
mxHuber Jun 5, 2024
bbe775a
fixed all but one test in IDEInstInteractionAnalysisTest
mxHuber Jun 6, 2024
c235afc
fixed all but two tests
mxHuber Jun 6, 2024
311cb68
Fix IIAFlowFact equality
fabianbs96 Jun 7, 2024
04a895d
fixed some newly failed tests
mxHuber Jun 12, 2024
e31c5ae
trade soundness for precision in LLVMAliasSet
fabianbs96 Jun 12, 2024
b6f4a10
Merge remote-tracking branch 'upstream/development' into f-clang-15
mxHuber Jun 12, 2024
e8c7f65
ci.yml update
mxHuber Jun 12, 2024
c3081ed
Revert "fixed some newly failed tests"
mxHuber Jun 12, 2024
6ced614
pre-commit hook
mxHuber Jun 12, 2024
12a9d06
Two Tests + xtaint09 test fix for pipeline
mxHuber Jun 12, 2024
9f5902a
Basic Opaque Pointer Impl, bugged
mxHuber Jun 13, 2024
812e6cb
switching to DebugInfoFinder
mxHuber Jun 13, 2024
8f89d1d
re-add the quick-fix for LLVMTypeHierarchy
fabianbs96 Jun 16, 2024
2bfffa8
OpaquePtr type mapping, missing subroutines
mxHuber Jun 17, 2024
2a91b6d
Introducing a pass to save ptr types
mxHuber Jun 18, 2024
d581987
Revert "Introducing a pass to save ptr types"
mxHuber Jun 19, 2024
9eb9929
moving phasar to DIBasedTypeHierarchy
mxHuber Jun 19, 2024
0b7575e
full switch to DIBasedTypeHierarchy + Test fixes
mxHuber Jun 23, 2024
5b39a18
fixed PathTracingTest
mxHuber Jun 25, 2024
85b0f24
dtaresolver deprecated and test fixes
mxHuber Jul 1, 2024
16c4a8e
Fixed OTFTest
mxHuber Jul 1, 2024
0514c7d
trimmed trailing whitespace
mxHuber Jul 1, 2024
2d8c9d8
minor fixes
mxHuber Jul 10, 2024
4463625
readded TypeToDIType map for RTAResolver
mxHuber Jul 10, 2024
df7d190
pre-commit clang-format fix
mxHuber Jul 10, 2024
ce2c6e8
pre-commit clang-format llvmbasedicfg.cpp
mxHuber Jul 10, 2024
8a4d812
moved RTAResolver to DITypes
mxHuber Jul 10, 2024
fd11ada
implemented review suggestions
mxHuber Aug 4, 2024
9c7f378
Log error if trying to instantiate DTAResolver + minor
fabianbs96 Aug 6, 2024
022b426
Add breaking changes
fabianbs96 Aug 6, 2024
d482f4d
Merge branch 'development' into f-clang-15
fabianbs96 Aug 8, 2024
b4783b9
Also compare gep type in IIA EqualGEPDescriptor
fabianbs96 Aug 9, 2024
49707eb
Merge branch 'development' into f-clang-15
fabianbs96 Aug 9, 2024
3848eef
Merge branch 'development' into f-clang-15
fabianbs96 Oct 4, 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
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.
- 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
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
2 changes: 1 addition & 1 deletion cmake/add_llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ macro(add_llvm)

if (NOT PHASAR_IN_TREE)
# Only search for LLVM if we build out of tree
find_package(LLVM 14 REQUIRED CONFIG)
find_package(LLVM 15 REQUIRED CONFIG)
find_library(LLVM_LIBRARY NAMES LLVM PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH)

if(USE_LLVM_FAT_LIB AND ${LLVM_LIBRARY} STREQUAL "LLVM_LIBRARY-NOTFOUND")
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 @@ -128,7 +121,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 -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file}
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} opt -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 @@ -102,7 +98,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB,
const nlohmann::json &SerializedCG);

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

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

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

Expand All @@ -28,12 +28,12 @@ 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;

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

Expand Down
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);

~CHAResolver() override = default;

Expand All @@ -39,7 +39,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
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 @@ -41,9 +43,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 @@ -85,7 +86,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
Loading