Skip to content

Commit 751a984

Browse files
fabianbs96mxHuberfabianbs
authored
Opaque Pointers Integration (#730)
* replaced llvm-14 with llvm-15 in relevant files * annotation fix + test fix * removed bitcasts and fixed tests * Fix Annotation.cpp + TaintConfigTest * Quick-fix LLVMTypeHierarchyTest * fix one IIA test * Fix StringtestCpp for generalized LCA * first half of tests fixed * fixed first half of tests * fixed all but one test in IDEInstInteractionAnalysisTest * fixed all but two tests * Fix IIAFlowFact equality * fixed some newly failed tests * trade soundness for precision in LLVMAliasSet * ci.yml update * Revert "fixed some newly failed tests" * pre-commit hook * Two Tests + xtaint09 test fix for pipeline * Basic Opaque Pointer Impl, bugged * switching to DebugInfoFinder * re-add the quick-fix for LLVMTypeHierarchy * OpaquePtr type mapping, missing subroutines * Introducing a pass to save ptr types * Revert "Introducing a pass to save ptr types" This reverts commit 2a91b6d. * moving phasar to DIBasedTypeHierarchy * full switch to DIBasedTypeHierarchy + Test fixes * fixed PathTracingTest * dtaresolver deprecated and test fixes * Fixed OTFTest * trimmed trailing whitespace * minor fixes * readded TypeToDIType map for RTAResolver * pre-commit clang-format fix * pre-commit clang-format llvmbasedicfg.cpp * moved RTAResolver to DITypes * implemented review suggestions * Log error if trying to instantiate DTAResolver + minor * Add breaking changes * Also compare gep type in IIA EqualGEPDescriptor * debugging CI * debugging * DITH fix attempt for CI * fix build * Start adding more sophisticated type extraction (WIP) * Handle function calls in getVarTypeFromIR * better fallback handling for getDebugLocation, etc * cleanup getVarTypeFromIR * Add libzstd-dev as apt dependency; otherwise the docker build fails on arm --------- Co-authored-by: mxHuber <huber.maximilian.leo@gmail.com> Co-authored-by: Fabian Schiebel <fabianbs@mail.uni-paderborn.de>
1 parent f8cca83 commit 751a984

File tree

99 files changed

+1167
-946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1167
-946
lines changed

BreakingChanges.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## development HEAD
44

5+
- 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.
6+
- 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.
57
- Removed the phasar-library `phasar_controller`. It is now part of the tool `phasar-cli`.
68
- The API of the `TypeHierarchy` interface (and thus the `LLVMTypeHierarchy` and `DIBasedTypeHierarchy` as well) has changed:
79
- No handling of the super-type relation (only sub-types)

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM
312312

313313
# LLVM
314314
if (NOT PHASAR_LLVM_VERSION)
315-
set(PHASAR_LLVM_VERSION 14)
315+
set(PHASAR_LLVM_VERSION 15)
316316
endif()
317317
include(add_llvm)
318318
add_llvm()

bootstrap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ source ./utils/safeCommandsSet.sh
66

77
readonly PHASAR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
88
PHASAR_INSTALL_DIR="/usr/local/phasar"
9-
LLVM_INSTALL_DIR="/usr/local/llvm-14"
9+
LLVM_INSTALL_DIR="/usr/local/llvm-15"
1010

1111
NUM_THREADS=$(nproc)
12-
LLVM_RELEASE=llvmorg-14.0.6
12+
LLVM_RELEASE=llvmorg-15.0.7
1313
DO_UNIT_TEST=true
1414
DO_INSTALL=false
1515
BUILD_TYPE=Release

cmake/phasar_macros.cmake

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,6 @@ function(generate_ll_file)
163163
set(GEN_C_FLAGS -fno-discard-value-names -emit-llvm -S -w)
164164
set(GEN_CMD_COMMENT "[LL]")
165165

166-
string(REGEX MATCH "clang\\+*-?[0-9]*$" compiler "${CMAKE_CXX_COMPILER}")
167-
if (compiler)
168-
if(PHASAR_LLVM_VERSION GREATER_EQUAL 15)
169-
list(APPEND GEN_CXX_FLAGS -Xclang -no-opaque-pointers)
170-
endif()
171-
172-
if(PHASAR_LLVM_VERSION GREATER_EQUAL 15)
173-
list(APPEND GEN_C_FLAGS -Xclang -no-opaque-pointers)
174-
endif()
175-
endif()
176-
177166
if(GEN_LL_MEM2REG)
178167
list(APPEND GEN_CXX_FLAGS -Xclang -disable-O0-optnone)
179168
list(APPEND GEN_C_FLAGS -Xclang -disable-O0-optnone)
@@ -219,7 +208,7 @@ function(generate_ll_file)
219208
add_custom_command(
220209
OUTPUT ${test_code_ll_file}
221210
COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file}
222-
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} ${opt} -mem2reg -S -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file}
211+
COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} ${opt} -mem2reg -S ${test_code_ll_file} -o ${test_code_ll_file}
223212
COMMENT ${GEN_CMD_COMMENT}
224213
DEPENDS ${GEN_LL_FILE}
225214
VERBATIM

include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class IDESolver
121121
llvm::StringRef(NToString(Cells[I].getRowKey())).trim().str();
122122

123123
std::string NodeStr =
124-
ICF->getFunctionName(ICF->getFunctionOf(Curr)) + "::" + NStr;
124+
ICF->getFunctionName(ICF->getFunctionOf(Curr)).str() + "::" + NStr;
125125
J[DataFlowID][NodeStr];
126126
std::string FactStr =
127127
llvm::StringRef(DToString(Cells[I].getColumnKey())).trim().str();

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedCallGraphBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
namespace psr {
1818
class LLVMProjectIRDB;
1919
enum class CallGraphAnalysisType;
20-
class LLVMTypeHierarchy;
20+
class DIBasedTypeHierarchy;
2121
class LLVMVFTableProvider;
2222
class Resolver;
2323

2424
[[nodiscard]] LLVMBasedCallGraph
2525
buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, CallGraphAnalysisType CGType,
2626
llvm::ArrayRef<const llvm::Function *> EntryPoints,
27-
LLVMTypeHierarchy &TH, LLVMVFTableProvider &VTP,
27+
DIBasedTypeHierarchy &TH, LLVMVFTableProvider &VTP,
2828
LLVMAliasInfoRef PT = nullptr,
2929
Soundness S = Soundness::Soundy);
3030

@@ -36,7 +36,7 @@ buildLLVMBasedCallGraph(const LLVMProjectIRDB &IRDB, Resolver &CGResolver,
3636
[[nodiscard]] LLVMBasedCallGraph
3737
buildLLVMBasedCallGraph(LLVMProjectIRDB &IRDB, CallGraphAnalysisType CGType,
3838
llvm::ArrayRef<std::string> EntryPoints,
39-
LLVMTypeHierarchy &TH, LLVMVFTableProvider &VTP,
39+
DIBasedTypeHierarchy &TH, LLVMVFTableProvider &VTP,
4040
LLVMAliasInfoRef PT = nullptr,
4141
Soundness S = Soundness::Soundy);
4242

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636
#include "llvm/IR/Value.h"
3737
#include "llvm/Support/raw_ostream.h"
3838

39-
#include <memory>
40-
4139
namespace psr {
42-
class LLVMTypeHierarchy;
40+
class DIBasedTypeHierarchy;
4341
class LLVMProjectIRDB;
4442
class Resolver;
4543

@@ -73,7 +71,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
7371
/// IRDB. True by default
7472
explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB, CallGraphAnalysisType CGType,
7573
llvm::ArrayRef<std::string> EntryPoints = {},
76-
LLVMTypeHierarchy *TH = nullptr,
74+
DIBasedTypeHierarchy *TH = nullptr,
7775
LLVMAliasInfoRef PT = nullptr,
7876
Soundness S = Soundness::Soundy,
7977
bool IncludeGlobals = true);
@@ -93,7 +91,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
9391
explicit LLVMBasedICFG(const LLVMProjectIRDB *IRDB,
9492
const CallGraphData &SerializedCG);
9593

96-
// Deleter of LLVMTypeHierarchy may be unknown here...
94+
// Deleter of DIBasedTypeHierarchy may be unknown here...
9795
~LLVMBasedICFG();
9896

9997
LLVMBasedICFG(const LLVMBasedICFG &) = delete;

include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace llvm {
1818
class Module;
19-
class StructType;
19+
class DIType;
2020
class GlobalVariable;
2121
} // namespace llvm
2222

@@ -28,12 +28,12 @@ class LLVMVFTableProvider {
2828
explicit LLVMVFTableProvider(const llvm::Module &Mod);
2929
explicit LLVMVFTableProvider(const LLVMProjectIRDB &IRDB);
3030

31-
[[nodiscard]] bool hasVFTable(const llvm::StructType *Type) const;
31+
[[nodiscard]] bool hasVFTable(const llvm::DIType *Type) const;
3232
[[nodiscard]] const LLVMVFTable *
33-
getVFTableOrNull(const llvm::StructType *Type) const;
33+
getVFTableOrNull(const llvm::DIType *Type) const;
3434

3535
private:
36-
std::unordered_map<const llvm::StructType *, LLVMVFTable> TypeVFTMap;
36+
std::unordered_map<const llvm::DIType *, LLVMVFTable> TypeVFTMap;
3737
};
3838
} // namespace psr
3939

include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class CallBase;
2525
} // namespace llvm
2626

2727
namespace psr {
28-
class LLVMTypeHierarchy;
28+
class DIBasedTypeHierarchy;
2929
class CHAResolver : public Resolver {
3030
public:
3131
CHAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP,
32-
const LLVMTypeHierarchy *TH);
32+
const DIBasedTypeHierarchy *TH);
3333

3434
// Deleting an incomplete type (LLVMTypeHierarchy) is UB, so instantiate the
3535
// dtor in CHAResolver.cpp
@@ -45,7 +45,7 @@ class CHAResolver : public Resolver {
4545
}
4646

4747
protected:
48-
MaybeUniquePtr<const LLVMTypeHierarchy, true> TH;
48+
MaybeUniquePtr<const DIBasedTypeHierarchy, true> TH;
4949
};
5050
} // namespace psr
5151

include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h"
2121
#include "phasar/PhasarLLVM/Pointer/TypeGraphs/CachedTypeGraph.h"
22+
#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"
2223
// To switch the TypeGraph
2324
// #include "phasar/PhasarLLVM/Pointer/TypeGraphs/LazyTypeGraph.h"
2425

@@ -33,12 +34,13 @@ class BitCastInst;
3334

3435
namespace psr {
3536

36-
class DTAResolver : public CHAResolver {
37+
class [[deprecated("Does not work with opaque pointers anymore")]] DTAResolver
38+
: public CHAResolver {
3739
public:
3840
using TypeGraph_t = CachedTypeGraph;
3941

4042
DTAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP,
41-
const LLVMTypeHierarchy *TH);
43+
const DIBasedTypeHierarchy *TH);
4244

4345
~DTAResolver() override = default;
4446

@@ -48,8 +50,8 @@ class DTAResolver : public CHAResolver {
4850

4951
[[nodiscard]] std::string str() const override;
5052

51-
[[nodiscard]] bool
52-
mutatesHelperAnalysisInformation() const noexcept override {
53+
[[nodiscard]] bool mutatesHelperAnalysisInformation()
54+
const noexcept override {
5355
return false;
5456
}
5557

@@ -60,13 +62,14 @@ class DTAResolver : public CHAResolver {
6062
* An heuristic that return true if the bitcast instruction is interesting to
6163
* take into the DTA relational graph
6264
*/
63-
static bool
64-
heuristicAntiConstructorThisType(const llvm::BitCastInst *BitCast);
65+
static bool heuristicAntiConstructorThisType(
66+
const llvm::BitCastInst *BitCast);
6567

6668
/**
6769
* Another heuristic that return true if the bitcast instruction is
6870
* interesting to take into the DTA relational graph (use the presence or not
6971
* of vtable)
72+
7073
*/
7174
bool heuristicAntiConstructorVtablePos(const llvm::BitCastInst *BitCast);
7275
};

0 commit comments

Comments
 (0)