diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79c2de56c..5967f993c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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: diff --git a/BreakingChanges.md b/BreakingChanges.md index 7792543ab..f9b008ecf 100644 --- a/BreakingChanges.md +++ b/BreakingChanges.md @@ -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) diff --git a/Dockerfile b/Dockerfile index 2bed11717..9317cbbad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 @@ -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 diff --git a/bootstrap.sh b/bootstrap.sh index 345d88570..0d829f265 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -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 diff --git a/cmake/add_llvm.cmake b/cmake/add_llvm.cmake index 7cf3ceb94..b4544620a 100644 --- a/cmake/add_llvm.cmake +++ b/cmake/add_llvm.cmake @@ -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") diff --git a/cmake/phasar_macros.cmake b/cmake/phasar_macros.cmake index 2ce5cd45f..3a6d28dbb 100644 --- a/cmake/phasar_macros.cmake +++ b/cmake/phasar_macros.cmake @@ -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) @@ -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 diff --git a/include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h b/include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h index 9f10b10e2..3ef1014f8 100644 --- a/include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h +++ b/include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h @@ -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(); diff --git a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h index 7cd8e7182..ce87d2795 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h +++ b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h @@ -33,12 +33,8 @@ #include "llvm/IR/Value.h" #include "llvm/Support/raw_ostream.h" -#include "nlohmann/json.hpp" - -#include - namespace psr { -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; class LLVMProjectIRDB; class Resolver; @@ -82,7 +78,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase { /// IRDB. True by default explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB, CallGraphAnalysisType CGType, llvm::ArrayRef EntryPoints = {}, - LLVMTypeHierarchy *TH = nullptr, + DIBasedTypeHierarchy *TH = nullptr, LLVMAliasInfoRef PT = nullptr, Soundness S = Soundness::Soundy, bool IncludeGlobals = true); @@ -102,7 +98,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase { 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; diff --git a/include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h b/include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h index 4206070fc..1fdc8100b 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h +++ b/include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h @@ -16,7 +16,7 @@ namespace llvm { class Module; -class StructType; +class DIType; class GlobalVariable; } // namespace llvm @@ -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 TypeVFTMap; + std::unordered_map TypeVFTMap; }; } // namespace psr diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h index 299a600ea..e38d12db4 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h @@ -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; @@ -39,7 +39,7 @@ class CHAResolver : public Resolver { [[nodiscard]] std::string str() const override; protected: - MaybeUniquePtr TH; + MaybeUniquePtr TH; }; } // namespace psr diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h index 7b4484f6e..a93721c25 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h @@ -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" @@ -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; @@ -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; diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h index e278cf786..24f5a0f0d 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h @@ -35,7 +35,7 @@ class Value; namespace psr { -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; class OTFResolver : public Resolver { protected: diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h index 6010443f0..c891f0d57 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h @@ -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; @@ -41,9 +43,9 @@ class RTAResolver : public CHAResolver { [[nodiscard]] std::string str() const override; private: - void resolveAllocatedStructTypes(); + void resolveAllocatedCompositeTypes(); - std::vector AllocatedStructTypes; + std::vector AllocatedCompositeTypes; }; } // namespace psr diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h index e8f997f17..158385c3e 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h @@ -20,6 +20,7 @@ #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/IR/DerivedTypes.h" #include #include @@ -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 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); @@ -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: @@ -85,7 +86,7 @@ class Resolver { static std::unique_ptr create(CallGraphAnalysisType Ty, const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP, - const LLVMTypeHierarchy *TH, + const DIBasedTypeHierarchy *TH, LLVMAliasInfoRef PT = nullptr); }; } // namespace psr diff --git a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.h b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.h index df91bce7d..d1e1ffce7 100644 --- a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.h +++ b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.h @@ -32,7 +32,7 @@ class StructType; namespace psr { class LLVMBasedICFG; -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; class InterMonoFullConstantPropagation : public IntraMonoFullConstantPropagation, @@ -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 EntryPoints = {}); diff --git a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.h b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.h index 8674ff564..a280365a5 100644 --- a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.h +++ b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.h @@ -36,7 +36,7 @@ class StructType; namespace psr { -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; struct InterMonoSolverTestDomain : LLVMAnalysisDomainDefault { using mono_container_t = BitVectorSet; @@ -52,8 +52,9 @@ class InterMonoSolverTest : public InterMonoProblem { 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 EntryPoints = {}); ~InterMonoSolverTest() override = default; diff --git a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.h b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.h index 211de3a91..7a78746ec 100644 --- a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.h +++ b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.h @@ -37,7 +37,7 @@ class StructType; namespace psr { -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; struct InterMonoTaintAnalysisDomain : LLVMAnalysisDomainDefault { using mono_container_t = BitVectorSet; @@ -56,8 +56,9 @@ class InterMonoTaintAnalysis using ConfigurationTy = LLVMTaintConfig; InterMonoTaintAnalysis(const LLVMProjectIRDB *IRDB, - const LLVMTypeHierarchy *TH, const LLVMBasedICFG *ICF, - LLVMAliasInfoRef PT, const LLVMTaintConfig &Config, + const DIBasedTypeHierarchy *TH, + const LLVMBasedICFG *ICF, LLVMAliasInfoRef PT, + const LLVMTaintConfig &Config, std::vector EntryPoints = {}); ~InterMonoTaintAnalysis() override = default; diff --git a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.h b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.h index 010e2f517..0bebfc4e6 100644 --- a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.h +++ b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.h @@ -42,7 +42,7 @@ namespace psr { class LLVMBasedCFG; class LLVMBasedICFG; -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; class InterMonoFullConstantPropagation; struct IntraMonoFCAFact { @@ -81,7 +81,7 @@ class IntraMonoFullConstantPropagation public: IntraMonoFullConstantPropagation(const LLVMProjectIRDB *IRDB, - const LLVMTypeHierarchy *TH, + const DIBasedTypeHierarchy *TH, const LLVMBasedCFG *CF, LLVMAliasInfoRef PT, std::vector EntryPoints = {}); diff --git a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.h b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.h index 13c5ac42f..75e31f25e 100644 --- a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.h +++ b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.h @@ -37,7 +37,7 @@ namespace psr { class LLVMBasedCFG; class LLVMBasedICFG; -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; struct IntraMonoSolverTestAnalysisDomain : public LLVMAnalysisDomainDefault { using mono_container_t = BitVectorSet; @@ -54,8 +54,9 @@ class IntraMonoSolverTest using i_t = IntraMonoSolverTestAnalysisDomain::i_t; using mono_container_t = IntraMonoSolverTestAnalysisDomain::mono_container_t; - IntraMonoSolverTest(const LLVMProjectIRDB *IRDB, const LLVMTypeHierarchy *TH, - const LLVMBasedCFG *CF, LLVMAliasInfoRef PT, + IntraMonoSolverTest(const LLVMProjectIRDB *IRDB, + const DIBasedTypeHierarchy *TH, const LLVMBasedCFG *CF, + LLVMAliasInfoRef PT, std::vector EntryPoints = {}); ~IntraMonoSolverTest() override = default; diff --git a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.h b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.h index e813e38d3..b08b91179 100644 --- a/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.h +++ b/include/phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.h @@ -28,7 +28,7 @@ class StructType; namespace psr { -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; class LLVMBasedCFG; class LLVMBasedICFG; @@ -48,8 +48,8 @@ class IntraMonoUninitVariables using mono_container_t = IntraMonoUninitVariablesDomain::mono_container_t; IntraMonoUninitVariables(const LLVMProjectIRDB *IRDB, - const LLVMTypeHierarchy *TH, const LLVMBasedCFG *CF, - LLVMAliasInfoRef PT, + const DIBasedTypeHierarchy *TH, + const LLVMBasedCFG *CF, LLVMAliasInfoRef PT, std::vector EntryPoints = {}); ~IntraMonoUninitVariables() override = default; diff --git a/include/phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h b/include/phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h index 11490fe20..755bbc923 100644 --- a/include/phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h +++ b/include/phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h @@ -17,6 +17,7 @@ class Value; class Instruction; class StructType; class Function; +class DIType; } // namespace llvm namespace psr { @@ -28,7 +29,7 @@ struct LLVMAnalysisDomainDefault : public AnalysisDomain { using d_t = const llvm::Value *; using n_t = const llvm::Instruction *; using f_t = const llvm::Function *; - using t_t = const llvm::StructType *; + using t_t = const llvm::DIType *; using v_t = const llvm::Value *; using c_t = LLVMBasedCFG; using i_t = LLVMBasedICFG; diff --git a/include/phasar/PhasarLLVM/HelperAnalyses.h b/include/phasar/PhasarLLVM/HelperAnalyses.h index f8cb8029b..2c6f06000 100644 --- a/include/phasar/PhasarLLVM/HelperAnalyses.h +++ b/include/phasar/PhasarLLVM/HelperAnalyses.h @@ -26,7 +26,7 @@ class Module; namespace psr { class LLVMProjectIRDB; -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; class LLVMBasedICFG; class LLVMBasedCFG; class LLVMAliasSet; @@ -60,14 +60,14 @@ class HelperAnalyses { // NOLINT(cppcoreguidelines-special-member-functions) [[nodiscard]] LLVMProjectIRDB &getProjectIRDB(); [[nodiscard]] LLVMAliasSet &getAliasInfo(); - [[nodiscard]] LLVMTypeHierarchy &getTypeHierarchy(); + [[nodiscard]] DIBasedTypeHierarchy &getTypeHierarchy(); [[nodiscard]] LLVMBasedICFG &getICFG(); [[nodiscard]] LLVMBasedCFG &getCFG(); private: std::unique_ptr IRDB; std::unique_ptr PT; - std::unique_ptr TH; + std::unique_ptr TH; std::unique_ptr ICF; std::unique_ptr CFG; diff --git a/include/phasar/PhasarLLVM/SimpleAnalysisConstructor.h b/include/phasar/PhasarLLVM/SimpleAnalysisConstructor.h index fce91ea9c..e6e80094a 100644 --- a/include/phasar/PhasarLLVM/SimpleAnalysisConstructor.h +++ b/include/phasar/PhasarLLVM/SimpleAnalysisConstructor.h @@ -19,7 +19,7 @@ namespace psr { class LLVMProjectIRDB; class LLVMAliasSet; class LLVMBasedICFG; -class LLVMTypeHierarchy; +class DIBasedTypeHierarchy; template ProblemTy createAnalysisProblem(HelperAnalyses &HA, ArgTys &&...Args) { @@ -46,13 +46,13 @@ ProblemTy createAnalysisProblem(HelperAnalyses &HA, ArgTys &&...Args) { std::forward(Args)...); } else if constexpr (std::is_constructible_v< ProblemTy, const LLVMProjectIRDB *, - const LLVMTypeHierarchy *, const LLVMBasedCFG *, + const DIBasedTypeHierarchy *, const LLVMBasedCFG *, LLVMAliasSet *, ArgTys...>) { return ProblemTy(&HA.getProjectIRDB(), &HA.getTypeHierarchy(), &HA.getCFG(), &HA.getAliasInfo(), std::forward(Args)...); } else if constexpr (std::is_constructible_v< ProblemTy, const LLVMProjectIRDB *, - const LLVMTypeHierarchy *, const LLVMBasedICFG *, + const DIBasedTypeHierarchy *, const LLVMBasedICFG *, LLVMAliasSet *, ArgTys...>) { return ProblemTy(&HA.getProjectIRDB(), &HA.getTypeHierarchy(), &HA.getICFG(), &HA.getAliasInfo(), diff --git a/include/phasar/PhasarLLVM/TypeHierarchy.h b/include/phasar/PhasarLLVM/TypeHierarchy.h index a8a9b4d12..7f9c9d607 100644 --- a/include/phasar/PhasarLLVM/TypeHierarchy.h +++ b/include/phasar/PhasarLLVM/TypeHierarchy.h @@ -10,6 +10,7 @@ #ifndef PHASAR_PHASARLLVM_TYPEHIERARCHY_H #define PHASAR_PHASARLLVM_TYPEHIERARCHY_H +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h" diff --git a/include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h b/include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h index dc7df6ea4..aa260bab3 100644 --- a/include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h +++ b/include/phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h @@ -31,9 +31,20 @@ class DIBasedTypeHierarchy using ClassType = const llvm::DIType *; using f_t = const llvm::Function *; + static inline constexpr llvm::StringLiteral StructPrefix = "struct."; + static inline constexpr llvm::StringLiteral ClassPrefix = "class."; + static inline constexpr llvm::StringLiteral VTablePrefix = "_ZTV"; + static inline constexpr llvm::StringLiteral VTablePrefixDemang = + "vtable for "; + static inline constexpr llvm::StringLiteral PureVirtualCallName = + "__cxa_pure_virtual"; + explicit DIBasedTypeHierarchy(const LLVMProjectIRDB &IRDB); ~DIBasedTypeHierarchy() override = default; + static bool isVTable(llvm::StringRef VarName); + static std::string removeVTablePrefix(llvm::StringRef VarName); + [[nodiscard]] bool hasType(ClassType Type) const override { return TypeToVertex.count(Type); } @@ -83,6 +94,7 @@ class DIBasedTypeHierarchy void printAsDot(llvm::raw_ostream &OS = llvm::outs()) const; [[nodiscard]] nlohmann::json getAsJson() const override; + void printAsJson(llvm::raw_ostream &OS = llvm::outs()) const; private: [[nodiscard]] llvm::iterator_range diff --git a/include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h b/include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h index fd55a006a..0386f83e7 100644 --- a/include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h +++ b/include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h @@ -22,6 +22,7 @@ class ConstantStruct; } // namespace llvm namespace psr { +class DIBasedTypeHierarchy; /** * @brief Represents a virtual method table. @@ -30,8 +31,8 @@ namespace psr { * virtual method table matters. */ class LLVMVFTable : public VFTable { + private: - friend class LLVMTypeHierarchy; friend class DIBasedTypeHierarchy; std::vector VFT; diff --git a/include/phasar/PhasarLLVM/Utils/LLVMIRToSrc.h b/include/phasar/PhasarLLVM/Utils/LLVMIRToSrc.h index 9432e9c92..b36149fbe 100644 --- a/include/phasar/PhasarLLVM/Utils/LLVMIRToSrc.h +++ b/include/phasar/PhasarLLVM/Utils/LLVMIRToSrc.h @@ -17,6 +17,8 @@ #ifndef PHASAR_PHASARLLVM_UTILS_LLVMIRTOSRC_H #define PHASAR_PHASARLLVM_UTILS_LLVMIRTOSRC_H +#include "llvm/IR/DebugInfoMetadata.h" + #include "nlohmann/json.hpp" #include @@ -58,6 +60,8 @@ getLineAndColFromIR(const llvm::Value *V); [[nodiscard]] std::string getModuleIDFromIR(const llvm::Value *V); +[[nodiscard]] llvm::DILocalVariable *getDILocalVariable(const llvm::Value *V); + struct SourceCodeInfo { std::string SourceCodeLine; std::string SourceCodeFilename; diff --git a/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp b/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp index f8e56c182..6deae92cb 100644 --- a/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp +++ b/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp @@ -17,11 +17,9 @@ #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMBasedContainerConfig.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" -#include "phasar/Utils/MaybeUniquePtr.h" #include "phasar/Utils/PAMMMacros.h" #include "phasar/Utils/Soundness.h" @@ -107,7 +105,7 @@ void LLVMBasedICFG::Builder::initGlobalsAndWorkList(LLVMBasedICFG *ICFG, UserEntryPoints.end()); } // Note: Pre-allocate the call-graph builder *after* adding the - // CRuntimeGlobalCtorsDtorsModel + // CRuntimeGlobalCtorsDtorsModel. CGBuilder.reserve(IRDB->getNumFunctions()); } @@ -338,7 +336,7 @@ void LLVMBasedICFG::initialize(LLVMProjectIRDB *IRDB, Resolver &CGResolver, LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB, CallGraphAnalysisType CGType, llvm::ArrayRef EntryPoints, - LLVMTypeHierarchy *TH, LLVMAliasInfoRef PT, + DIBasedTypeHierarchy *TH, LLVMAliasInfoRef PT, Soundness S, bool IncludeGlobals) : IRDB(IRDB), VTP(*IRDB) { assert(IRDB != nullptr); diff --git a/lib/PhasarLLVM/ControlFlow/LLVMVFTableProvider.cpp b/lib/PhasarLLVM/ControlFlow/LLVMVFTableProvider.cpp index b34384bd2..43c6dab56 100644 --- a/lib/PhasarLLVM/ControlFlow/LLVMVFTableProvider.cpp +++ b/lib/PhasarLLVM/ControlFlow/LLVMVFTableProvider.cpp @@ -1,65 +1,89 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h" +#include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h" #include "phasar/Utils/Logger.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Demangle/Demangle.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Casting.h" using namespace psr; +static std::string getTypeName(const llvm::DIType *DITy) { + if (const auto *CompTy = llvm::dyn_cast(DITy)) { + auto Ident = CompTy->getIdentifier(); + return Ident.empty() ? llvm::demangle(CompTy->getName().str()) + : llvm::demangle(Ident.str()); + } + return llvm::demangle(DITy->getName().str()); +} + static std::vector getVirtualFunctions( const llvm::StringMap &ClearNameTVMap, - const llvm::StructType &Type) { - auto ClearName = LLVMTypeHierarchy::removeStructOrClassPrefix(Type.getName()); + const llvm::DIType *Type) { + auto ClearName = getTypeName(Type); + + static constexpr llvm::StringLiteral TIPrefix = "typeinfo name for "; + if (llvm::StringRef(ClearName).startswith(TIPrefix)) { + ClearName = ClearName.substr(TIPrefix.size()); + } auto It = ClearNameTVMap.find(ClearName); if (It != ClearNameTVMap.end()) { - if (const auto *TI = llvm::dyn_cast(It->second)) { - if (!TI->hasInitializer()) { - PHASAR_LOG_LEVEL_CAT(DEBUG, "LLVMTypeHierarchy", - ClearName << " does not have initializer"); - return {}; - } - if (const auto *I = - llvm::dyn_cast(TI->getInitializer())) { - return LLVMVFTable::getVFVectorFromIRVTable(*I); - } + if (!It->second->hasInitializer()) { + PHASAR_LOG_LEVEL_CAT(DEBUG, "DIBasedTypeHierarchy", + ClearName << " does not have initializer"); + return {}; + } + if (const auto *I = llvm::dyn_cast( + It->second->getInitializer())) { + return LLVMVFTable::getVFVectorFromIRVTable(*I); } } return {}; } LLVMVFTableProvider::LLVMVFTableProvider(const llvm::Module &Mod) { - auto StructTypes = Mod.getIdentifiedStructTypes(); llvm::StringMap ClearNameTVMap; for (const auto &Glob : Mod.globals()) { - if (LLVMTypeHierarchy::isVTable(Glob.getName())) { + if (DIBasedTypeHierarchy::isVTable(Glob.getName())) { auto Demang = llvm::demangle(Glob.getName().str()); - auto ClearName = LLVMTypeHierarchy::removeVTablePrefix(Demang); + auto ClearName = DIBasedTypeHierarchy::removeVTablePrefix(Demang); ClearNameTVMap.try_emplace(ClearName, &Glob); } } - for (const auto *Ty : StructTypes) { - TypeVFTMap.try_emplace(Ty, getVirtualFunctions(ClearNameTVMap, *Ty)); + llvm::DebugInfoFinder DIF; + DIF.processModule(Mod); + for (const auto *Ty : DIF.types()) { + if (const auto *CompTy = llvm::dyn_cast(Ty)) { + if (CompTy->getTag() == llvm::dwarf::DW_TAG_class_type || + CompTy->getTag() == llvm::dwarf::DW_TAG_structure_type) { + TypeVFTMap.try_emplace(CompTy, + getVirtualFunctions(ClearNameTVMap, CompTy)); + } + } } } LLVMVFTableProvider::LLVMVFTableProvider(const LLVMProjectIRDB &IRDB) : LLVMVFTableProvider(*IRDB.getModule()) {} -bool LLVMVFTableProvider::hasVFTable(const llvm::StructType *Type) const { +bool LLVMVFTableProvider::hasVFTable(const llvm::DIType *Type) const { return TypeVFTMap.count(Type); } const LLVMVFTable * -LLVMVFTableProvider::getVFTableOrNull(const llvm::StructType *Type) const { +LLVMVFTableProvider::getVFTableOrNull(const llvm::DIType *Type) const { auto It = TypeVFTMap.find(Type); return It != TypeVFTMap.end() ? &It->second : nullptr; } diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/CHAResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/CHAResolver.cpp index 6b2c144a5..89ebe3bc6 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/CHAResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/CHAResolver.cpp @@ -16,6 +16,7 @@ #include "phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" @@ -33,10 +34,10 @@ using namespace psr; CHAResolver::CHAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP, - const LLVMTypeHierarchy *TH) + const DIBasedTypeHierarchy *TH) : Resolver(IRDB, VTP), TH(TH) { if (!TH) { - this->TH = std::make_unique(*IRDB); + this->TH = std::make_unique(*IRDB); } } diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/DTAResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/DTAResolver.cpp index eed109422..7863c024a 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/DTAResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/DTAResolver.cpp @@ -17,12 +17,13 @@ #include "phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h" #include "phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" #include "phasar/Utils/Utilities.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstIterator.h" @@ -30,6 +31,9 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" #include @@ -37,11 +41,13 @@ using namespace psr; DTAResolver::DTAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP, - const LLVMTypeHierarchy *TH) + const DIBasedTypeHierarchy *TH) : CHAResolver(IRDB, VTP, TH) {} bool DTAResolver::heuristicAntiConstructorThisType( const llvm::BitCastInst *BitCast) { + llvm::report_fatal_error("Does not work with opaque pointers anymore"); +#if 0 // We check if the caller is a constructor, and if the this argument has the // same type as the source type of the bitcast. If it is the case, it returns // false, true otherwise. @@ -59,13 +65,18 @@ bool DTAResolver::heuristicAntiConstructorThisType( } return true; +#endif } bool DTAResolver::heuristicAntiConstructorVtablePos( const llvm::BitCastInst *BitCast) { + llvm::report_fatal_error("Does not work with opaque pointers anymore"); +#if 0 + // Better heuristic than the previous one, can handle the CRTP. Based on the // previous one. + if (heuristicAntiConstructorThisType(BitCast)) { return true; } @@ -139,9 +150,12 @@ bool DTAResolver::heuristicAntiConstructorVtablePos( } return (BitcastNum > VtableNum); +#endif } void DTAResolver::otherInst(const llvm::Instruction *Inst) { + llvm::report_fatal_error("Does not work with opaque pointers anymore"); +#if 0 if (Inst->getType()->isOpaquePointerTy()) { /// XXX: We may want to get these information on a different way, e.g. by /// analyzing the debug info @@ -162,10 +176,12 @@ void DTAResolver::otherInst(const llvm::Instruction *Inst) { TypeGraph.addLink(DestStructType, SrcStructType); } } +#endif } - auto DTAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) -> FunctionSetTy { + llvm::report_fatal_error("Does not work with opaque pointers anymore"); +#if 0 FunctionSetTy PossibleCallTargets; PHASAR_LOG_LEVEL(DEBUG, @@ -185,7 +201,7 @@ auto DTAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) PHASAR_LOG_LEVEL(DEBUG, "Virtual function table entry is: " << VtableIndex); - const auto *ReceiverType = getReceiverType(CallSite); + const auto *ReceiverType = getReceiverStructType(CallSite); auto PossibleTypes = TypeGraph.getTypes(ReceiverType); @@ -217,6 +233,7 @@ auto DTAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) #endif return PossibleCallTargets; +#endif } std::string DTAResolver::str() const { return "DTA"; } diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp index c1f783d54..be2dbe913 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp @@ -11,7 +11,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" #include "phasar/Utils/Utilities.h" @@ -94,7 +94,7 @@ auto OTFResolver::resolveVirtualCall(const llvm::CallBase *CallSite) for (const auto *P : *PTS) { if (const auto *PGV = llvm::dyn_cast(P)) { if (PGV->hasName() && - PGV->getName().startswith(LLVMTypeHierarchy::VTablePrefix) && + PGV->getName().startswith(DIBasedTypeHierarchy::VTablePrefix) && PGV->hasInitializer()) { if (const auto *PCS = llvm::dyn_cast(PGV->getInitializer())) { @@ -104,7 +104,7 @@ auto OTFResolver::resolveVirtualCall(const llvm::CallBase *CallSite) } const auto *Callee = VFs[VtableIndex]; if (Callee == nullptr || !Callee->hasName() || - Callee->getName() == LLVMTypeHierarchy::PureVirtualCallName || + Callee->getName() == DIBasedTypeHierarchy::PureVirtualCallName || !isConsistentCall(CallSite, Callee)) { continue; } diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp index 27ec5c5a1..05342b05a 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp @@ -17,13 +17,13 @@ #include "phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" #include "phasar/Utils/Utilities.h" -#include "llvm/ADT/StringSet.h" -#include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstIterator.h" @@ -31,15 +31,16 @@ #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Casting.h" using namespace std; using namespace psr; RTAResolver::RTAResolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP, - const LLVMTypeHierarchy *TH) + const DIBasedTypeHierarchy *TH) : CHAResolver(IRDB, VTP, TH) { - resolveAllocatedStructTypes(); + resolveAllocatedCompositeTypes(); } auto RTAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) @@ -70,17 +71,13 @@ auto RTAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) auto ReachableTypes = TH->getSubTypes(ReceiverType); // also insert all possible subtypes vtable entries - auto EndIt = ReachableTypes.end(); - for (const auto *PossibleType : AllocatedStructTypes) { - if (const auto *PossibleTypeStruct = - llvm::dyn_cast(PossibleType)) { - if (ReachableTypes.find(PossibleTypeStruct) != EndIt) { - const auto *Target = getNonPureVirtualVFTEntry(PossibleTypeStruct, - VtableIndex, CallSite); - if (Target) { - PossibleCallTargets.insert(Target); - } + for (const auto *PossibleType : AllocatedCompositeTypes) { + if (ReachableTypes.find(PossibleType) != EndIt) { + const auto *Target = + getNonPureVirtualVFTEntry(PossibleType, VtableIndex, CallSite); + if (Target) { + PossibleCallTargets.insert(Target); } } } @@ -95,61 +92,17 @@ auto RTAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) std::string RTAResolver::str() const { return "RTA"; } /// More or less copied from GeneralStatisticsAnalysis -void RTAResolver::resolveAllocatedStructTypes() { - if (!AllocatedStructTypes.empty()) { +void RTAResolver::resolveAllocatedCompositeTypes() { + if (!AllocatedCompositeTypes.empty()) { return; } - llvm::DenseSet AllocatedStructTypes; - - for (const auto *Fun : IRDB->getAllFunctions()) { - for (const auto &Inst : llvm::instructions(Fun)) { - if (const auto *Alloca = llvm::dyn_cast(&Inst)) { - if (const auto *StructTy = - llvm::dyn_cast(Alloca->getAllocatedType())) { - AllocatedStructTypes.insert(StructTy); - } - } else if (const auto *CallSite = llvm::dyn_cast(&Inst); - CallSite && CallSite->getCalledFunction()) { - // check if an instance of a user-defined type is allocated on the - // heap - - if (!isHeapAllocatingFunction(CallSite->getCalledFunction())) { - continue; - } - /// TODO: Does this iteration over the users make sense? - /// After LLVM 15 we will probably not be able to access the - /// PointerElementType anyway... - for (const auto *User : Inst.users()) { - const auto *Cast = llvm::dyn_cast(User); - if (!Cast || Cast->getDestTy()->isOpaquePointerTy() || - !Cast->getDestTy() - ->getNonOpaquePointerElementType() - ->isStructTy()) { - continue; - } - // finally check for ctor call - for (const auto *User : Cast->users()) { - if (const auto *CTor = llvm::dyn_cast(User)) { - // potential call to the structures ctor - if (CTor->getCalledFunction() && - getNthFunctionArgument(CTor->getCalledFunction(), 0) - ->getType() == Cast->getDestTy() && - !Cast->getDestTy()->isOpaquePointerTy()) { - if (const auto *StructTy = llvm::dyn_cast( - Cast->getDestTy()->getNonOpaquePointerElementType())) { - AllocatedStructTypes.insert(StructTy); - } - } - } - } - } - } + llvm::DebugInfoFinder DIF; + DIF.processModule(*IRDB->getModule()); + + for (const auto *Ty : DIF.types()) { + if (const auto *CompTy = llvm::dyn_cast(Ty)) { + AllocatedCompositeTypes.push_back(CompTy); } } - - this->AllocatedStructTypes.reserve(AllocatedStructTypes.size()); - this->AllocatedStructTypes.insert(this->AllocatedStructTypes.end(), - AllocatedStructTypes.begin(), - AllocatedStructTypes.end()); } diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp index 745a4e866..dda9fec28 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp @@ -24,16 +24,21 @@ #include "phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h" #include "phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" +#include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" #include #include @@ -57,7 +62,7 @@ std::optional psr::getVFTIndex(const llvm::CallBase *CallSite) { return std::nullopt; } -const llvm::StructType *psr::getReceiverType(const llvm::CallBase *CallSite) { +const llvm::DIType *psr::getReceiverType(const llvm::CallBase *CallSite) { if (CallSite->arg_empty() || (CallSite->hasStructRetAttr() && CallSite->arg_size() < 2)) { return nullptr; @@ -70,16 +75,12 @@ const llvm::StructType *psr::getReceiverType(const llvm::CallBase *CallSite) { return nullptr; } - if (Receiver->getType()->isOpaquePointerTy()) { - llvm::errs() << "WARNING: The IR under analysis uses opaque pointers, " - "which are not supported by phasar yet!\n"; - return nullptr; - } - - if (!Receiver->getType()->isOpaquePointerTy()) { - if (const auto *ReceiverTy = llvm::dyn_cast( - Receiver->getType()->getNonOpaquePointerElementType())) { - return ReceiverTy; + if (const auto *Load = llvm::dyn_cast(Receiver)) { + if (const auto *DITy = getDILocalVariable(Load->getPointerOperand())) { + if (const auto *DerivedTy = + llvm::dyn_cast(DITy->getType())) { + return DerivedTy->getBaseType(); + } } } @@ -115,21 +116,26 @@ Resolver::Resolver(const LLVMProjectIRDB *IRDB) : IRDB(IRDB), VTP(nullptr) { } Resolver::Resolver(const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP) - : IRDB(IRDB), VTP(VTP) {} + : IRDB(IRDB), VTP(VTP) { + assert(IRDB != nullptr); +} const llvm::Function * -Resolver::getNonPureVirtualVFTEntry(const llvm::StructType *T, unsigned Idx, +Resolver::getNonPureVirtualVFTEntry(const llvm::DIType *T, unsigned Idx, const llvm::CallBase *CallSite) { if (!VTP) { return nullptr; } + if (const auto *VT = VTP->getVFTableOrNull(T)) { const auto *Target = VT->getFunction(Idx); - if (Target && Target->getName() != LLVMTypeHierarchy::PureVirtualCallName && + if (Target && + Target->getName() != DIBasedTypeHierarchy::PureVirtualCallName && isConsistentCall(CallSite, Target)) { return Target; } } + return nullptr; } @@ -163,7 +169,7 @@ void Resolver::otherInst(const llvm::Instruction *Inst) {} std::unique_ptr Resolver::create(CallGraphAnalysisType Ty, const LLVMProjectIRDB *IRDB, const LLVMVFTableProvider *VTP, - const LLVMTypeHierarchy *TH, + const DIBasedTypeHierarchy *TH, LLVMAliasInfoRef PT) { assert(IRDB != nullptr); assert(VTP != nullptr); @@ -179,7 +185,10 @@ std::unique_ptr Resolver::create(CallGraphAnalysisType Ty, return std::make_unique(IRDB, VTP, TH); case CallGraphAnalysisType::DTA: assert(TH != nullptr); - return std::make_unique(IRDB, VTP, TH); + PHASAR_LOG_LEVEL(ERROR, "Do not use the DTA resolver anymore. It relies on " + "the removed 'typed-pointers' feature of LLVM."); + std::exit(1); + // return std::make_unique(IRDB, VTP, TH); case CallGraphAnalysisType::VTA: llvm::report_fatal_error( "The VTA callgraph algorithm is not implemented yet"); diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp index 7ce08382f..b4f0ddfcb 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp @@ -30,6 +30,7 @@ #include "llvm/Demangle/Demangle.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instructions.h" @@ -424,21 +425,20 @@ IDEGeneralizedLCA::getCallToRetEdgeFunction(IDEGeneralizedLCA::n_t CallSite, // found correct place and time if (CallNode == getZeroValue() && RetSiteNode == CS->getArgOperand(0)) { // find string literal that is used to initialize the string - if (auto *User = llvm::dyn_cast(CS->getArgOperand(1))) { - if (auto *GV = - llvm::dyn_cast(User->getOperand(0))) { - if (!GV->hasInitializer()) { - // in this case we don't know the initial value statically - // return ALLBOTTOM; - return AllBottom{}; - } - if (auto *CDA = llvm::dyn_cast( - GV->getInitializer())) { - if (CDA->isCString()) { - // here we statically know the string literal the std::string is - // initialized with - return GenConstant{l_t({EdgeValue(CDA->getAsCString().str())})}; - } + const auto *Arg1 = CS->getArgOperand(1)->stripPointerCastsAndAliases(); + + if (const auto *GV = llvm::dyn_cast(Arg1)) { + if (!GV->hasInitializer()) { + // in this case we don't know the initial value statically + // return ALLBOTTOM; + return AllBottom{}; + } + if (const auto *CDA = + llvm::dyn_cast(GV->getInitializer())) { + if (CDA->isCString()) { + // here we statically know the string literal the std::string is + // initialized with + return GenConstant{l_t({EdgeValue(CDA->getAsCString().str())})}; } } } diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp index d65e8ea9c..2952fc354 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp @@ -11,6 +11,7 @@ #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Value.h" @@ -69,7 +70,8 @@ IDEIIAFlowFact IDEIIAFlowFact::create(const llvm::Value *BaseVal) { } return {BaseVal, FieldDesc}; } - llvm::report_fatal_error("Unexpected instruction!"); + llvm::report_fatal_error("Unexpected instruction!" + + llvm::Twine(llvmIRToString(BaseVal))); } bool IDEIIAFlowFact::flowFactEqual(const IDEIIAFlowFact &Other) const { @@ -107,9 +109,8 @@ bool IDEIIAFlowFact::operator==(const IDEIIAFlowFact &Other) const { } auto EqualGEPDescriptor = [](const llvm::GetElementPtrInst *Lhs, const llvm::GetElementPtrInst *Rhs) { - const auto *LhsI = llvm::dyn_cast(Lhs); - const auto *RhsI = llvm::dyn_cast(Rhs); - return LhsI->isSameOperationAs(RhsI); + return Lhs->getSourceElementType() == Rhs->getSourceElementType() && + llvm::equal(Lhs->indices(), Rhs->indices()); }; for (unsigned Idx = 0; Idx < FieldDesc.size(); ++Idx) { if (!EqualGEPDescriptor(FieldDesc[Idx], Other.FieldDesc[Idx])) { diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp index b2c2365b9..8f5630d23 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp @@ -12,7 +12,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/BitVectorSet.h" @@ -34,7 +34,7 @@ using namespace psr; namespace psr { InterMonoFullConstantPropagation::InterMonoFullConstantPropagation( - const LLVMProjectIRDB *IRDB, const LLVMTypeHierarchy *TH, + const LLVMProjectIRDB *IRDB, const DIBasedTypeHierarchy *TH, const LLVMBasedICFG *ICF, LLVMAliasInfoRef PT, std::vector EntryPoints) : IntraMonoFullConstantPropagation(IRDB, TH, ICF, PT, diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.cpp index 5d14d7fa4..51b8a9260 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoSolverTest.cpp @@ -12,7 +12,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Utilities.h" @@ -26,7 +26,7 @@ namespace psr { InterMonoSolverTest::InterMonoSolverTest(const LLVMProjectIRDB *IRDB, - const LLVMTypeHierarchy *TH, + const DIBasedTypeHierarchy *TH, const LLVMBasedICFG *ICF, LLVMAliasInfoRef PT, std::vector EntryPoints) diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.cpp index 04830d72c..2d552d64c 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoTaintAnalysis.cpp @@ -13,7 +13,7 @@ #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" #include "phasar/PhasarLLVM/TaintConfig/TaintConfigUtilities.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/BitVectorSet.h" #include "phasar/Utils/Logger.h" @@ -31,7 +31,7 @@ namespace psr { InterMonoTaintAnalysis::InterMonoTaintAnalysis( - const LLVMProjectIRDB *IRDB, const LLVMTypeHierarchy *TH, + const LLVMProjectIRDB *IRDB, const DIBasedTypeHierarchy *TH, const LLVMBasedICFG *ICF, LLVMAliasInfoRef PT, const LLVMTaintConfig &Config, std::vector EntryPoints) : InterMonoProblem(IRDB, TH, ICF, PT, diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp index 41aeb91a4..ca659b551 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp @@ -13,7 +13,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/BitVectorSet.h" @@ -43,7 +43,7 @@ using namespace psr; namespace psr { IntraMonoFullConstantPropagation::IntraMonoFullConstantPropagation( - const LLVMProjectIRDB *IRDB, const LLVMTypeHierarchy *TH, + const LLVMProjectIRDB *IRDB, const DIBasedTypeHierarchy *TH, const LLVMBasedCFG *CF, LLVMAliasInfoRef PT, std::vector EntryPoints) : IntraMonoProblem( diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.cpp index dc0a9782d..8d59c0683 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.cpp @@ -19,7 +19,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "llvm/IR/Instruction.h" @@ -34,7 +34,7 @@ using namespace psr; namespace psr { IntraMonoSolverTest::IntraMonoSolverTest(const LLVMProjectIRDB *IRDB, - const LLVMTypeHierarchy *TH, + const DIBasedTypeHierarchy *TH, const LLVMBasedCFG *CF, LLVMAliasInfoRef PT, std::vector EntryPoints) diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.cpp index 3d7aa3a8a..ebbe5e586 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoUninitVariables.cpp @@ -12,7 +12,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/BitVectorSet.h" @@ -29,7 +29,7 @@ using namespace psr; namespace psr { IntraMonoUninitVariables::IntraMonoUninitVariables( - const LLVMProjectIRDB *IRDB, const LLVMTypeHierarchy *TH, + const LLVMProjectIRDB *IRDB, const DIBasedTypeHierarchy *TH, const LLVMBasedCFG *CF, LLVMAliasInfoRef PT, std::vector EntryPoints) : IntraMonoProblem(IRDB, TH, CF, PT, diff --git a/lib/PhasarLLVM/HelperAnalyses.cpp b/lib/PhasarLLVM/HelperAnalyses.cpp index 815f9d887..ce9b2f095 100644 --- a/lib/PhasarLLVM/HelperAnalyses.cpp +++ b/lib/PhasarLLVM/HelperAnalyses.cpp @@ -3,7 +3,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include #include @@ -79,9 +79,9 @@ LLVMAliasSet &HelperAnalyses::getAliasInfo() { return *PT; } -LLVMTypeHierarchy &HelperAnalyses::getTypeHierarchy() { +DIBasedTypeHierarchy &HelperAnalyses::getTypeHierarchy() { if (!TH) { - TH = std::make_unique(getProjectIRDB()); + TH = std::make_unique(getProjectIRDB()); } return *TH; } diff --git a/lib/PhasarLLVM/Pointer/LLVMAliasSet.cpp b/lib/PhasarLLVM/Pointer/LLVMAliasSet.cpp index 83e796b6b..ebf8af538 100644 --- a/lib/PhasarLLVM/Pointer/LLVMAliasSet.cpp +++ b/lib/PhasarLLVM/Pointer/LLVMAliasSet.cpp @@ -23,6 +23,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/MemoryLocation.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" @@ -36,6 +37,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/TypeSize.h" #include "nlohmann/json.hpp" @@ -315,24 +317,42 @@ bool LLVMAliasSet::intraIsReachableAllocationSiteTy( return false; } +static llvm::Type *getPointeeTypeOrNull(const llvm::Value *Ptr) { + assert(Ptr->getType()->isPointerTy()); + + if (!Ptr->getType()->isOpaquePointerTy()) { + return Ptr->getType()->getNonOpaquePointerElementType(); + } + + if (const auto *Arg = llvm::dyn_cast(Ptr)) { + if (auto *Ty = Arg->getParamByValType()) { + return Ty; + } + if (auto *Ty = Arg->getParamStructRetType()) { + return Ty; + } + } + if (const auto *Alloca = llvm::dyn_cast(Ptr)) { + return Alloca->getAllocatedType(); + } + return nullptr; +} + static bool mayAlias(llvm::AAResults &AA, const llvm::DataLayout &DL, const llvm::Value *V, const llvm::Value *Rep) { assert(V->getType()->isPointerTy()); assert(Rep->getType()->isPointerTy()); - auto *ElTy = !V->getType()->isOpaquePointerTy() - ? V->getType()->getNonOpaquePointerElementType() - : nullptr; - auto *RepElTy = !Rep->getType()->isOpaquePointerTy() - ? Rep->getType()->getNonOpaquePointerElementType() - : nullptr; + auto *ElTy = getPointeeTypeOrNull(V); + auto *RepElTy = getPointeeTypeOrNull(Rep); - auto VSize = ElTy && ElTy->isSized() ? DL.getTypeStoreSize(ElTy) - : llvm::MemoryLocation::UnknownSize; + auto VSize = ElTy && ElTy->isSized() + ? llvm::LocationSize::precise(DL.getTypeStoreSize(ElTy)) + : llvm::LocationSize::precise(1); auto RepSize = RepElTy && RepElTy->isSized() - ? DL.getTypeStoreSize(RepElTy) - : llvm::MemoryLocation::UnknownSize; + ? llvm::LocationSize::precise(DL.getTypeStoreSize(RepElTy)) + : llvm::LocationSize::precise(1); if (AA.alias(V, VSize, Rep, RepSize) != llvm::AliasResult::NoAlias) { return true; diff --git a/lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.cpp b/lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.cpp index fd01a0759..b3c60c310 100644 --- a/lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.cpp +++ b/lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.cpp @@ -207,6 +207,25 @@ auto DIBasedTypeHierarchy::subTypesOf(ClassType Ty) const noexcept return subTypesOf(It->second); } +bool DIBasedTypeHierarchy::isVTable(llvm::StringRef VarName) { + if (VarName.startswith(VTablePrefix)) { + return true; + } + // In LLVM 16 demangle() takes a StringRef + auto Demang = llvm::demangle(VarName.str()); + return llvm::StringRef(Demang).startswith(VTablePrefixDemang); +} + +std::string DIBasedTypeHierarchy::removeVTablePrefix(llvm::StringRef VarName) { + if (VarName.startswith(VTablePrefixDemang)) { + return VarName.drop_front(VTablePrefixDemang.size()).str(); + } + if (VarName.startswith(VTablePrefix)) { + return VarName.drop_front(VTablePrefix.size()).str(); + } + return VarName.str(); +} + void DIBasedTypeHierarchy::print(llvm::raw_ostream &OS) const { { OS << "Type Hierarchy:\n"; @@ -241,6 +260,11 @@ void DIBasedTypeHierarchy::print(llvm::raw_ostream &OS) const { llvm::report_fatal_error("Not implemented"); } +void DIBasedTypeHierarchy::printAsJson(llvm::raw_ostream &OS) const { + /// TODO: implement + llvm::report_fatal_error("Not implemented"); +} + void DIBasedTypeHierarchy::printAsDot(llvm::raw_ostream &OS) const { OS << "digraph TypeHierarchy{\n"; scope_exit CloseBrace = [&OS] { OS << "}\n"; }; diff --git a/lib/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.cpp b/lib/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.cpp index 2fe8ac954..66fcba08a 100644 --- a/lib/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.cpp +++ b/lib/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.cpp @@ -88,10 +88,12 @@ LLVMTypeHierarchy::removeStructOrClassPrefix(const llvm::StructType &T) { std::string LLVMTypeHierarchy::removeStructOrClassPrefix(llvm::StringRef TypeName) { if (TypeName.startswith(StructPrefix)) { - return TypeName.drop_front(StructPrefix.size()).str(); + TypeName = TypeName.drop_front(StructPrefix.size()); + } else if (TypeName.startswith(ClassPrefix)) { + TypeName = TypeName.drop_front(ClassPrefix.size()); } - if (TypeName.startswith(ClassPrefix)) { - return TypeName.drop_front(ClassPrefix.size()).str(); + if (TypeName.endswith(".base")) { + TypeName = TypeName.drop_back(llvm::StringRef(".base").size()); } return TypeName.str(); } @@ -172,18 +174,15 @@ LLVMTypeHierarchy::getSubTypes(const llvm::Module & /*M*/, if (const auto *I = llvm::dyn_cast(TI->getInitializer())) { for (const auto &Op : I->operands()) { - if (auto *CE = llvm::dyn_cast(Op)) { - if (auto *BC = llvm::dyn_cast(CE)) { - if (BC->getOperand(0)->hasName()) { - auto Name = BC->getOperand(0)->getName(); - if (Name.find(TypeInfoPrefix) != llvm::StringRef::npos) { - auto ClearName = - removeTypeInfoPrefix(llvm::demangle(Name.str())); - if (auto TyIt = ClearNameTypeMap.find(ClearName); - TyIt != ClearNameTypeMap.end()) { - SubTypes.push_back(TyIt->second); - } - } + const auto *CE = Op->stripPointerCastsAndAliases(); + + if (CE->hasName()) { + auto Name = CE->getName(); + if (Name.find(TypeInfoPrefix) != llvm::StringRef::npos) { + auto ClearName = removeTypeInfoPrefix(llvm::demangle(Name.str())); + if (auto TyIt = ClearNameTypeMap.find(ClearName); + TyIt != ClearNameTypeMap.end()) { + SubTypes.push_back(TyIt->second); } } } @@ -268,8 +267,9 @@ LLVMTypeHierarchy::getSubTypes(const llvm::StructType *Type) const { return {}; } -const llvm::StructType * -LLVMTypeHierarchy::getType(llvm::StringRef TypeName) const { +template +static const llvm::StructType *getTypeImpl(const GraphT &TypeGraph, + llvm::StringRef TypeName) { for (auto V : boost::make_iterator_range(boost::vertices(TypeGraph))) { if (TypeGraph[V].Type->getName() == TypeName) { return TypeGraph[V].Type; @@ -278,6 +278,15 @@ LLVMTypeHierarchy::getType(llvm::StringRef TypeName) const { return nullptr; } +const llvm::StructType * +LLVMTypeHierarchy::getType(llvm::StringRef TypeName) const { + if (const auto *Ty = getTypeImpl(TypeGraph, TypeName)) { + return Ty; + } + + return getTypeImpl(TypeGraph, (TypeName + ".base").str()); +} + std::vector LLVMTypeHierarchy::getAllTypes() const { std::vector Types; Types.reserve(boost::num_vertices(TypeGraph)); diff --git a/lib/PhasarLLVM/TypeHierarchy/LLVMVFTable.cpp b/lib/PhasarLLVM/TypeHierarchy/LLVMVFTable.cpp index 76c2f7c82..20d09dff2 100644 --- a/lib/PhasarLLVM/TypeHierarchy/LLVMVFTable.cpp +++ b/lib/PhasarLLVM/TypeHierarchy/LLVMVFTable.cpp @@ -58,22 +58,10 @@ LLVMVFTable::getVFVectorFromIRVTable(const llvm::ConstantStruct &VT) { // is RTTI for (const auto *It = std::next(CA->operands().begin(), 2); It != CA->operands().end(); ++It) { - const auto &COp = *It; - if (const auto *CE = llvm::dyn_cast(COp)) { - if (const auto *BC = llvm::dyn_cast(CE)) { - // if the entry is a GlobalAlias, get its Aliasee - auto *Entry = BC->getOperand(0); - while (auto *GA = llvm::dyn_cast(Entry)) { - Entry = GA->getAliasee(); - } - auto *F = llvm::dyn_cast(Entry); - VFS.push_back(F); - } else { - VFS.push_back(nullptr); - } - } else { - VFS.push_back(nullptr); - } + const auto *Entry = It->get()->stripPointerCastsAndAliases(); + + const auto *F = llvm::dyn_cast(Entry); + VFS.push_back(F); } } } diff --git a/lib/PhasarLLVM/Utils/Annotation.cpp b/lib/PhasarLLVM/Utils/Annotation.cpp index 07b5127b3..b97f2429a 100644 --- a/lib/PhasarLLVM/Utils/Annotation.cpp +++ b/lib/PhasarLLVM/Utils/Annotation.cpp @@ -10,6 +10,7 @@ #include "phasar/PhasarLLVM/Utils/Annotation.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" @@ -54,41 +55,32 @@ uint64_t VarAnnotation::getLine() const { } llvm::StringRef VarAnnotation::retrieveString(unsigned Idx) const { - if (const auto *ConstExpr = llvm::dyn_cast( - AnnotationCall->getArgOperand(Idx))) { - if (llvm::isa(ConstExpr)) { - if (const auto *GlobalVar = - llvm::dyn_cast(ConstExpr->getOperand(0))) { - if (GlobalVar->hasInitializer()) { - const auto *ConstData = GlobalVar->getInitializer(); - if (const auto *Data = - llvm::dyn_cast(ConstData)) { - return Data->getAsCString(); - } - } - } - } + assert(Idx < AnnotationCall->arg_size()); + const auto *StringPointer = llvm::dyn_cast( + llvm::getUnderlyingObject(AnnotationCall->getArgOperand(Idx))); + if (!StringPointer || !StringPointer->hasInitializer()) { + return ""; + } + + const auto *ConstData = StringPointer->getInitializer(); + if (const auto *Data = llvm::dyn_cast(ConstData)) { + return Data->getAsCString(); } + return ""; } const llvm::Value *VarAnnotation::getOriginalValueOrOriginalArg( const llvm::Value *AnnotatedValue) { - if (const auto *BitCast = - llvm::dyn_cast(AnnotatedValue)) { - // this may be already the original value - const auto *Value = BitCast->getOperand(0); - // check if that values originates from a formal parameter - for (const auto &User : Value->users()) { - if (const auto *Store = llvm::dyn_cast(User); - Store && llvm::isa(Store->getValueOperand())) { - return Store->getValueOperand(); - } + // check if that values originates from a formal parameter + for (const auto &User : AnnotatedValue->users()) { + if (const auto *Store = llvm::dyn_cast(User); + Store && llvm::isa(Store->getValueOperand())) { + return Store->getValueOperand(); } - return Value; } - return nullptr; + return AnnotatedValue; } GlobalAnnotation::GlobalAnnotation( @@ -96,33 +88,25 @@ GlobalAnnotation::GlobalAnnotation( : AnnotationStruct(AnnotationStruct) {} const llvm::Function *GlobalAnnotation::getFunction() const { - const auto *FunCastOp = AnnotationStruct->getOperand(0); - if (const auto *BitCast = llvm::dyn_cast(FunCastOp)) { - if (const auto *Fun = - llvm::dyn_cast(BitCast->getOperand(0))) { - return Fun; - } - } - return nullptr; + const auto *FunCastOp = + AnnotationStruct->getOperand(0)->stripPointerCastsAndAliases(); + + return llvm::dyn_cast(FunCastOp); } llvm::StringRef GlobalAnnotation::retrieveString(unsigned Idx) const { - const auto *AnnotationGepOp = AnnotationStruct->getOperand(Idx); - if (const auto *ConstExpr = - llvm::dyn_cast(AnnotationGepOp)) { - if (llvm::isa(ConstExpr)) { - if (const auto *GlobalVar = - llvm::dyn_cast(ConstExpr->getOperand(0))) { - if (GlobalVar->hasInitializer()) { - const auto *ConstData = GlobalVar->getInitializer(); - if (const auto *Data = - llvm::dyn_cast(ConstData)) { - return Data->getAsCString(); - } - } - } - } + assert(Idx < AnnotationStruct->getNumOperands()); + const auto *StringPointer = llvm::dyn_cast( + llvm::getUnderlyingObject(AnnotationStruct->getOperand(Idx))); + if (!StringPointer || !StringPointer->hasInitializer()) { + return ""; } + + const auto *ConstData = StringPointer->getInitializer(); + if (const auto *Data = llvm::dyn_cast(ConstData)) { + return Data->getAsCString(); + } + return ""; } diff --git a/lib/PhasarLLVM/Utils/LLVMIRToSrc.cpp b/lib/PhasarLLVM/Utils/LLVMIRToSrc.cpp index 01dd07603..49fdc29a3 100644 --- a/lib/PhasarLLVM/Utils/LLVMIRToSrc.cpp +++ b/lib/PhasarLLVM/Utils/LLVMIRToSrc.cpp @@ -12,7 +12,6 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Demangle/Demangle.h" -#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" @@ -56,7 +55,7 @@ static llvm::DbgVariableIntrinsic *getDbgVarIntrinsic(const llvm::Value *V) { return nullptr; } -static llvm::DILocalVariable *getDILocalVariable(const llvm::Value *V) { +llvm::DILocalVariable *psr::getDILocalVariable(const llvm::Value *V) { if (auto *DbgIntr = getDbgVarIntrinsic(V)) { if (auto *DDI = llvm::dyn_cast(DbgIntr)) { return DDI->getVariable(); diff --git a/lib/PhasarPass/PhasarPass.cpp b/lib/PhasarPass/PhasarPass.cpp index d16a1fb78..7d133b761 100644 --- a/lib/PhasarPass/PhasarPass.cpp +++ b/lib/PhasarPass/PhasarPass.cpp @@ -32,7 +32,7 @@ #include "phasar/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoSolverTest.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" #include "phasar/PhasarLLVM/TaintConfig/LLVMTaintConfig.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h" #include "phasar/PhasarPass/Options.h" #include "phasar/Utils/EnumFlags.h" @@ -62,7 +62,7 @@ bool PhasarPass::runOnModule(llvm::Module &M) { } // set up the call-graph algorithm to be used CallGraphAnalysisType CGTy = toCallGraphAnalysisType(CallGraphAnalysis); - LLVMTypeHierarchy H(DB); + DIBasedTypeHierarchy H(DB); LLVMAliasSet PT(&DB); // LLVMBasedCFG CFG; LLVMBasedICFG I(&DB, CGTy, EntryPoints, &H, &PT); diff --git a/test/build_systems_tests/advanced_project/main.c b/test/build_systems_tests/advanced_project/main.c index 3392c6793..d2acc3e97 100644 --- a/test/build_systems_tests/advanced_project/main.c +++ b/test/build_systems_tests/advanced_project/main.c @@ -1,5 +1,6 @@ #include "src1.h" #include "src2.h" + #include #include diff --git a/test/build_systems_tests/cmake_project/main.c b/test/build_systems_tests/cmake_project/main.c index d15fb9d8a..49b9262c2 100644 --- a/test/build_systems_tests/cmake_project/main.c +++ b/test/build_systems_tests/cmake_project/main.c @@ -1,5 +1,6 @@ // A simple program that computes the square root of a number #include "mysources/one_source.h" + #include #include diff --git a/test/build_systems_tests/nomechanism_project/main.cpp b/test/build_systems_tests/nomechanism_project/main.cpp index becd3c95e..b58ec4d7b 100644 --- a/test/build_systems_tests/nomechanism_project/main.cpp +++ b/test/build_systems_tests/nomechanism_project/main.cpp @@ -1,5 +1,6 @@ #include "source_1.h" #include "source_2.h" + #include using namespace std; diff --git a/test/build_systems_tests/nomechanism_project/source_1.cpp b/test/build_systems_tests/nomechanism_project/source_1.cpp index abbf3c2cc..e97704c26 100644 --- a/test/build_systems_tests/nomechanism_project/source_1.cpp +++ b/test/build_systems_tests/nomechanism_project/source_1.cpp @@ -1,4 +1,5 @@ #include "source_1.h" + #include "source_2.h" const int src1_const = 42; diff --git a/test/clang_test_code/SimpleProject/main.cpp b/test/clang_test_code/SimpleProject/main.cpp index 065d550eb..e86dd792a 100644 --- a/test/clang_test_code/SimpleProject/main.cpp +++ b/test/clang_test_code/SimpleProject/main.cpp @@ -13,6 +13,7 @@ */ #include "myfunctions.h" + #include using namespace std; diff --git a/test/json_test_code/exceptions/exceptions_01_cpp_icfg.json b/test/json_test_code/exceptions/exceptions_01_cpp_icfg.json index e93e96c4e..e1e54fda4 100644 --- a/test/json_test_code/exceptions/exceptions_01_cpp_icfg.json +++ b/test/json_test_code/exceptions/exceptions_01_cpp_icfg.json @@ -1,388 +1,118 @@ [ { "from": { - "IR": "%x = alloca i32, align 4 | ID: 1", - "column": 7, - "line": 5, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "int x = 42;" - }, - "to": { - "IR": "store i32 42, i32* %x, align 4 | ID: 3", - "column": 7, - "line": 5, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "int x = 42;" - } - }, - { - "from": { - "IR": "store i32 42, i32* %x, align 4 | ID: 3", - "column": 7, - "line": 5, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "int x = 42;" - }, - "to": { - "IR": "%call = call i32 @rand() | ID: 4", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - } - }, - { - "from": { - "IR": "%call = call i32 @rand() | ID: 4", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - }, - "to": { - "IR": "%tobool = icmp ne i32 %call, 0 | ID: 5", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - } - }, - { - "from": { - "IR": "%tobool = icmp ne i32 %call, 0 | ID: 5", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - }, - "to": { - "IR": "br i1 %tobool, label %if.then, label %if.else | ID: 6", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - } - }, - { - "from": { - "IR": "br i1 %tobool, label %if.then, label %if.else | ID: 6", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - }, - "to": { - "IR": "%0 = load i32, i32* %x, align 4 | ID: 7", - "column": 7, - "line": 7, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "x += 4;" - } - }, - { - "from": { - "IR": "br i1 %tobool, label %if.then, label %if.else | ID: 6", - "column": 7, - "line": 6, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "if (rand()) {" - }, - "to": { - "IR": "%exception = call i8* @__cxa_allocate_exception(i64 4) | ID: 11", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - } - }, - { - "from": { - "IR": "%0 = load i32, i32* %x, align 4 | ID: 7", - "column": 7, - "line": 7, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "x += 4;" - }, - "to": { - "IR": "%add = add nsw i32 %0, 4 | ID: 8", - "column": 7, - "line": 7, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "x += 4;" - } - }, - { - "from": { - "IR": "%add = add nsw i32 %0, 4 | ID: 8", - "column": 7, - "line": 7, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "x += 4;" - }, - "to": { - "IR": "store i32 %add, i32* %x, align 4 | ID: 9", - "column": 7, - "line": 7, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "x += 4;" - } - }, - { - "from": { - "IR": "store i32 %add, i32* %x, align 4 | ID: 9", - "column": 7, - "line": 7, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "x += 4;" - }, - "to": { - "IR": "br label %if.end | ID: 10", - "column": 3, - "line": 8, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "} else {" - } - }, - { - "from": { - "IR": "br label %if.end | ID: 10", - "column": 3, - "line": 8, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "} else {" - }, - "to": { - "IR": "%2 = load i32, i32* %x, align 4 | ID: 16", - "column": 10, - "line": 12, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "return x;" - } - }, - { - "from": { - "IR": "%exception = call i8* @__cxa_allocate_exception(i64 4) | ID: 11", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - }, - "to": { - "IR": "%1 = bitcast i8* %exception to i32* | ID: 12", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - } - }, - { - "from": { - "IR": "%1 = bitcast i8* %exception to i32* | ID: 12", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - }, - "to": { - "IR": "store i32 2353782, i32* %1, align 16 | ID: 13", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - } - }, - { - "from": { - "IR": "store i32 2353782, i32* %1, align 16 | ID: 13", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - }, - "to": { - "IR": "call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) | ID: 14", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - } - }, - { - "from": { - "IR": "call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) | ID: 14", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - }, - "to": { - "IR": "unreachable | ID: 15", - "column": 5, - "line": 9, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "throw 2353782;" - } - }, - { - "from": { - "IR": "%2 = load i32, i32* %x, align 4 | ID: 16", - "column": 10, - "line": 12, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "return x;" - }, - "to": { - "IR": "ret i32 %2 | ID: 17", - "column": 3, - "line": 12, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", - "sourceCodeFunctionName": "foo()", - "sourceCodeLine": "return x;" - } - }, - { - "from": { - "IR": "%retval = alloca i32, align 4 | ID: 18", + "IR": "%retval = alloca i32, align 4 | ID: 17", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" }, "to": { - "IR": "%a = alloca i32, align 4 | ID: 19", + "IR": "%a = alloca i32, align 4 | ID: 18", "column": 7, "line": 16, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "int a = 3;" } }, { "from": { - "IR": "%a = alloca i32, align 4 | ID: 19", + "IR": "%a = alloca i32, align 4 | ID: 18", "column": 7, "line": 16, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "int a = 3;" }, "to": { - "IR": "%exn.slot = alloca i8*, align 8 | ID: 20", + "IR": "%exn.slot = alloca ptr, align 8 | ID: 19", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" } }, { "from": { - "IR": "%exn.slot = alloca i8*, align 8 | ID: 20", + "IR": "%exn.slot = alloca ptr, align 8 | ID: 19", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" }, "to": { - "IR": "%ehselector.slot = alloca i32, align 4 | ID: 21", + "IR": "%ehselector.slot = alloca i32, align 4 | ID: 20", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" } }, { "from": { - "IR": "%ehselector.slot = alloca i32, align 4 | ID: 21", + "IR": "%ehselector.slot = alloca i32, align 4 | ID: 20", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" }, "to": { - "IR": "store i32 0, i32* %retval, align 4 | ID: 22", + "IR": "store i32 0, ptr %retval, align 4 | ID: 21", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" } }, { "from": { - "IR": "store i32 0, i32* %retval, align 4 | ID: 22", + "IR": "store i32 0, ptr %retval, align 4 | ID: 21", "column": 0, "line": 0, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "" }, "to": { - "IR": "store i32 3, i32* %a, align 4 | ID: 24", + "IR": "store i32 3, ptr %a, align 4 | ID: 23", "column": 7, "line": 16, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "int a = 3;" } }, { "from": { - "IR": "store i32 3, i32* %a, align 4 | ID: 24", + "IR": "store i32 3, ptr %a, align 4 | ID: 23", "column": 7, "line": 16, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "int a = 3;" }, "to": { - "IR": "%call = invoke i32 @_Z3foov()\n to label %invoke.cont unwind label %lpad | ID: 25", + "IR": "%call = invoke noundef i32 @_Z3foov()\n to label %invoke.cont unwind label %lpad | ID: 24", "column": 9, "line": 18, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = foo();" } }, { "from": { - "IR": "%call = invoke i32 @_Z3foov()\n to label %invoke.cont unwind label %lpad | ID: 25", + "IR": "%call = invoke noundef i32 @_Z3foov()\n to label %invoke.cont unwind label %lpad | ID: 24", "column": 9, "line": 18, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = foo();" }, @@ -390,35 +120,35 @@ "IR": "%x = alloca i32, align 4 | ID: 1", "column": 7, "line": 5, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "foo()", "sourceCodeLine": "int x = 42;" } }, { "from": { - "IR": "ret i32 %2 | ID: 17", + "IR": "ret i32 %1 | ID: 16", "column": 3, "line": 12, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "foo()", "sourceCodeLine": "return x;" }, "to": { - "IR": "store i32 %call, i32* %a, align 4 | ID: 26", + "IR": "store i32 %call, ptr %a, align 4 | ID: 25", "column": 7, "line": 18, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = foo();" } }, { "from": { - "IR": "%call = invoke i32 @_Z3foov()\n to label %invoke.cont unwind label %lpad | ID: 25", + "IR": "%call = invoke noundef i32 @_Z3foov()\n to label %invoke.cont unwind label %lpad | ID: 24", "column": 9, "line": 18, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = foo();" }, @@ -426,279 +156,531 @@ "IR": "%x = alloca i32, align 4 | ID: 1", "column": 7, "line": 5, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "foo()", "sourceCodeLine": "int x = 42;" } }, { "from": { - "IR": "ret i32 %2 | ID: 17", + "IR": "ret i32 %1 | ID: 16", "column": 3, "line": 12, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "foo()", "sourceCodeLine": "return x;" }, "to": { - "IR": "%0 = landingpad { i8*, i32 }\n catch i8* null | ID: 28", + "IR": "%0 = landingpad { ptr, i32 }\n catch ptr null | ID: 27", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "store i32 %call, i32* %a, align 4 | ID: 26", + "IR": "store i32 %call, ptr %a, align 4 | ID: 25", "column": 7, "line": 18, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = foo();" }, "to": { - "IR": "br label %try.cont | ID: 27", + "IR": "br label %try.cont | ID: 26", "column": 3, "line": 19, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "} catch (...) {" } }, { "from": { - "IR": "br label %try.cont | ID: 27", + "IR": "br label %try.cont | ID: 26", "column": 3, "line": 19, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "} catch (...) {" }, "to": { - "IR": "%4 = load i32, i32* %a, align 4 | ID: 39", + "IR": "%4 = load i32, ptr %a, align 4 | ID: 38", "column": 10, "line": 22, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "return a;" } }, { "from": { - "IR": "%0 = landingpad { i8*, i32 }\n catch i8* null | ID: 28", + "IR": "%0 = landingpad { ptr, i32 }\n catch ptr null | ID: 27", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "%1 = extractvalue { i8*, i32 } %0, 0 | ID: 29", + "IR": "%1 = extractvalue { ptr, i32 } %0, 0 | ID: 28", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "%1 = extractvalue { i8*, i32 } %0, 0 | ID: 29", + "IR": "%1 = extractvalue { ptr, i32 } %0, 0 | ID: 28", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "store i8* %1, i8** %exn.slot, align 8 | ID: 30", + "IR": "store ptr %1, ptr %exn.slot, align 8 | ID: 29", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "store i8* %1, i8** %exn.slot, align 8 | ID: 30", + "IR": "store ptr %1, ptr %exn.slot, align 8 | ID: 29", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "%2 = extractvalue { i8*, i32 } %0, 1 | ID: 31", + "IR": "%2 = extractvalue { ptr, i32 } %0, 1 | ID: 30", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "%2 = extractvalue { i8*, i32 } %0, 1 | ID: 31", + "IR": "%2 = extractvalue { ptr, i32 } %0, 1 | ID: 30", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "store i32 %2, i32* %ehselector.slot, align 4 | ID: 32", + "IR": "store i32 %2, ptr %ehselector.slot, align 4 | ID: 31", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "store i32 %2, i32* %ehselector.slot, align 4 | ID: 32", + "IR": "store i32 %2, ptr %ehselector.slot, align 4 | ID: 31", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "br label %catch | ID: 33", + "IR": "br label %catch | ID: 32", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "br label %catch | ID: 33", + "IR": "br label %catch | ID: 32", "column": 1, "line": 23, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "%exn = load i8*, i8** %exn.slot, align 8 | ID: 34", + "IR": "%exn = load ptr, ptr %exn.slot, align 8 | ID: 33", "column": 3, "line": 19, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "} catch (...) {" } }, { "from": { - "IR": "%exn = load i8*, i8** %exn.slot, align 8 | ID: 34", + "IR": "%exn = load ptr, ptr %exn.slot, align 8 | ID: 33", "column": 3, "line": 19, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "} catch (...) {" }, "to": { - "IR": "%3 = call i8* @__cxa_begin_catch(i8* %exn) | ID: 35", + "IR": "%3 = call ptr @__cxa_begin_catch(ptr %exn) | ID: 34", "column": 3, "line": 19, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "} catch (...) {" } }, { "from": { - "IR": "%3 = call i8* @__cxa_begin_catch(i8* %exn) | ID: 35", + "IR": "%3 = call ptr @__cxa_begin_catch(ptr %exn) | ID: 34", "column": 3, "line": 19, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "} catch (...) {" }, "to": { - "IR": "store i32 -1, i32* %a, align 4 | ID: 36", + "IR": "store i32 -1, ptr %a, align 4 | ID: 35", "column": 7, "line": 20, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = -1;" } }, { "from": { - "IR": "store i32 -1, i32* %a, align 4 | ID: 36", + "IR": "store i32 -1, ptr %a, align 4 | ID: 35", "column": 7, "line": 20, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "a = -1;" }, "to": { - "IR": "call void @__cxa_end_catch() | ID: 37", + "IR": "call void @__cxa_end_catch() | ID: 36", "column": 3, "line": 21, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "call void @__cxa_end_catch() | ID: 37", + "IR": "call void @__cxa_end_catch() | ID: 36", "column": 3, "line": 21, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "br label %try.cont | ID: 38", + "IR": "br label %try.cont | ID: 37", "column": 3, "line": 21, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" } }, { "from": { - "IR": "br label %try.cont | ID: 38", + "IR": "br label %try.cont | ID: 37", "column": 3, "line": 21, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "}" }, "to": { - "IR": "%4 = load i32, i32* %a, align 4 | ID: 39", + "IR": "%4 = load i32, ptr %a, align 4 | ID: 38", "column": 10, "line": 22, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "return a;" } }, { "from": { - "IR": "%4 = load i32, i32* %a, align 4 | ID: 39", + "IR": "%4 = load i32, ptr %a, align 4 | ID: 38", "column": 10, "line": 22, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "return a;" }, "to": { - "IR": "ret i32 %4 | ID: 40", + "IR": "ret i32 %4 | ID: 39", "column": 3, "line": 22, - "sourceCodeFileName": "/home/ubuntu/phasar/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", "sourceCodeFunctionName": "main", "sourceCodeLine": "return a;" } + }, + { + "from": { + "IR": "%x = alloca i32, align 4 | ID: 1", + "column": 7, + "line": 5, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "int x = 42;" + }, + "to": { + "IR": "store i32 42, ptr %x, align 4 | ID: 3", + "column": 7, + "line": 5, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "int x = 42;" + } + }, + { + "from": { + "IR": "store i32 42, ptr %x, align 4 | ID: 3", + "column": 7, + "line": 5, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "int x = 42;" + }, + "to": { + "IR": "%call = call i32 @rand() | ID: 4", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + } + }, + { + "from": { + "IR": "%call = call i32 @rand() | ID: 4", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + }, + "to": { + "IR": "%tobool = icmp ne i32 %call, 0 | ID: 5", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + } + }, + { + "from": { + "IR": "%tobool = icmp ne i32 %call, 0 | ID: 5", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + }, + "to": { + "IR": "br i1 %tobool, label %if.then, label %if.else | ID: 6", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + } + }, + { + "from": { + "IR": "br i1 %tobool, label %if.then, label %if.else | ID: 6", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + }, + "to": { + "IR": "%0 = load i32, ptr %x, align 4 | ID: 7", + "column": 7, + "line": 7, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "x += 4;" + } + }, + { + "from": { + "IR": "br i1 %tobool, label %if.then, label %if.else | ID: 6", + "column": 7, + "line": 6, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "if (rand()) {" + }, + "to": { + "IR": "%exception = call ptr @__cxa_allocate_exception(i64 4) | ID: 11", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + } + }, + { + "from": { + "IR": "%0 = load i32, ptr %x, align 4 | ID: 7", + "column": 7, + "line": 7, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "x += 4;" + }, + "to": { + "IR": "%add = add nsw i32 %0, 4 | ID: 8", + "column": 7, + "line": 7, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "x += 4;" + } + }, + { + "from": { + "IR": "%add = add nsw i32 %0, 4 | ID: 8", + "column": 7, + "line": 7, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "x += 4;" + }, + "to": { + "IR": "store i32 %add, ptr %x, align 4 | ID: 9", + "column": 7, + "line": 7, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "x += 4;" + } + }, + { + "from": { + "IR": "store i32 %add, ptr %x, align 4 | ID: 9", + "column": 7, + "line": 7, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "x += 4;" + }, + "to": { + "IR": "br label %if.end | ID: 10", + "column": 3, + "line": 8, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "} else {" + } + }, + { + "from": { + "IR": "br label %if.end | ID: 10", + "column": 3, + "line": 8, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "} else {" + }, + "to": { + "IR": "%1 = load i32, ptr %x, align 4 | ID: 15", + "column": 10, + "line": 12, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "return x;" + } + }, + { + "from": { + "IR": "%exception = call ptr @__cxa_allocate_exception(i64 4) | ID: 11", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + }, + "to": { + "IR": "store i32 2353782, ptr %exception, align 16 | ID: 12", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + } + }, + { + "from": { + "IR": "store i32 2353782, ptr %exception, align 16 | ID: 12", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + }, + "to": { + "IR": "call void @__cxa_throw(ptr %exception, ptr @_ZTIi, ptr null) | ID: 13", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + } + }, + { + "from": { + "IR": "call void @__cxa_throw(ptr %exception, ptr @_ZTIi, ptr null) | ID: 13", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + }, + "to": { + "IR": "unreachable | ID: 14", + "column": 5, + "line": 9, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "throw 2353782;" + } + }, + { + "from": { + "IR": "%1 = load i32, ptr %x, align 4 | ID: 15", + "column": 10, + "line": 12, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "return x;" + }, + "to": { + "IR": "ret i32 %1 | ID: 16", + "column": 3, + "line": 12, + "sourceCodeFileName": "/home/max/Desktop/dev/Arbeit/phasar-clones/phasar-f-clang-15/test/llvm_test_code/exceptions/exceptions_01.cpp", + "sourceCodeFunctionName": "foo()", + "sourceCodeLine": "return x;" + } } ] diff --git a/test/llvm_test_code/call_graphs/CMakeLists.txt b/test/llvm_test_code/call_graphs/CMakeLists.txt index 9b1b58ebe..9a4557b17 100644 --- a/test/llvm_test_code/call_graphs/CMakeLists.txt +++ b/test/llvm_test_code/call_graphs/CMakeLists.txt @@ -36,3 +36,7 @@ set(NoMem2regSources foreach(TEST_SRC ${NoMem2regSources}) generate_ll_file(FILE ${TEST_SRC}) endforeach(TEST_SRC) + +foreach(TEST_SRC ${NoMem2regSources}) + generate_ll_file(FILE ${TEST_SRC} DEBUG) +endforeach(TEST_SRC) diff --git a/test/llvm_test_code/globals/globals_ctor_2_2.cpp b/test/llvm_test_code/globals/globals_ctor_2_2.cpp index ee1e9ee25..597706ae2 100644 --- a/test/llvm_test_code/globals/globals_ctor_2_2.cpp +++ b/test/llvm_test_code/globals/globals_ctor_2_2.cpp @@ -1,7 +1,7 @@ -#include - #include "globals_ctor_2_1.h" +#include + int createBar() { return 234765; } int bar = createBar(); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation1.c b/test/llvm_test_code/openssl/key_derivation/key-derivation1.c index 32c37bc11..699fe9176 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation1.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation1.c @@ -1,9 +1,8 @@ -#include -#include - #include #include #include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation2.c b/test/llvm_test_code/openssl/key_derivation/key-derivation2.c index 4157bb564..d8b3c9975 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation2.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation2.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation3.c b/test/llvm_test_code/openssl/key_derivation/key-derivation3.c index c3f5ed1ab..808cea86f 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation3.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation3.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation4.c b/test/llvm_test_code/openssl/key_derivation/key-derivation4.c index f493de1dc..98a67b9a0 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation4.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation4.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation5.c b/test/llvm_test_code/openssl/key_derivation/key-derivation5.c index 2ddd53dcf..1169ff97b 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation5.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation5.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation6.c b/test/llvm_test_code/openssl/key_derivation/key-derivation6.c index 75985f1a8..6de7b8136 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation6.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation6.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation7.c b/test/llvm_test_code/openssl/key_derivation/key-derivation7.c index 0a3b822de..e89324b2c 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation7.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation7.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/key_derivation/key-derivation8.c b/test/llvm_test_code/openssl/key_derivation/key-derivation8.c index 3c844bcee..c9346523a 100644 --- a/test/llvm_test_code/openssl/key_derivation/key-derivation8.c +++ b/test/llvm_test_code/openssl/key_derivation/key-derivation8.c @@ -1,10 +1,9 @@ -#include -#include -#include - #include #include #include +#include +#include +#include void error(const char *fmt, ...); diff --git a/test/llvm_test_code/openssl/secure_heap/memory6.c b/test/llvm_test_code/openssl/secure_heap/memory6.c index 1859de3c6..891d134a9 100644 --- a/test/llvm_test_code/openssl/secure_heap/memory6.c +++ b/test/llvm_test_code/openssl/secure_heap/memory6.c @@ -1,9 +1,8 @@ +#include #include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/openssl/secure_heap/memory7.c b/test/llvm_test_code/openssl/secure_heap/memory7.c index 51861f178..4bb15f8a0 100644 --- a/test/llvm_test_code/openssl/secure_heap/memory7.c +++ b/test/llvm_test_code/openssl/secure_heap/memory7.c @@ -1,9 +1,8 @@ +#include #include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/openssl/secure_memory/memory1.c b/test/llvm_test_code/openssl/secure_memory/memory1.c index 926cc4bdb..7b5b18a48 100644 --- a/test/llvm_test_code/openssl/secure_memory/memory1.c +++ b/test/llvm_test_code/openssl/secure_memory/memory1.c @@ -1,8 +1,7 @@ +#include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/openssl/secure_memory/memory2.c b/test/llvm_test_code/openssl/secure_memory/memory2.c index dee6cb582..f8e42f9ab 100644 --- a/test/llvm_test_code/openssl/secure_memory/memory2.c +++ b/test/llvm_test_code/openssl/secure_memory/memory2.c @@ -1,8 +1,7 @@ +#include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/openssl/secure_memory/memory3.c b/test/llvm_test_code/openssl/secure_memory/memory3.c index 15189fbf0..70421c290 100644 --- a/test/llvm_test_code/openssl/secure_memory/memory3.c +++ b/test/llvm_test_code/openssl/secure_memory/memory3.c @@ -1,9 +1,8 @@ +#include #include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/openssl/secure_memory/memory4.c b/test/llvm_test_code/openssl/secure_memory/memory4.c index 5bd50fa1f..5fa16bd77 100644 --- a/test/llvm_test_code/openssl/secure_memory/memory4.c +++ b/test/llvm_test_code/openssl/secure_memory/memory4.c @@ -1,9 +1,8 @@ +#include #include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/openssl/secure_memory/memory5.c b/test/llvm_test_code/openssl/secure_memory/memory5.c index ce639ae55..1b1f9bb53 100644 --- a/test/llvm_test_code/openssl/secure_memory/memory5.c +++ b/test/llvm_test_code/openssl/secure_memory/memory5.c @@ -1,9 +1,8 @@ +#include #include #include #include -#include - void error(const char *fmt, ...); int main() { diff --git a/test/llvm_test_code/xtaint/xtaint08.cpp b/test/llvm_test_code/xtaint/xtaint08.cpp index 4246cccc9..70187ede5 100644 --- a/test/llvm_test_code/xtaint/xtaint08.cpp +++ b/test/llvm_test_code/xtaint/xtaint08.cpp @@ -1,5 +1,6 @@ #define PHASAR_ENABLE_TAINT_CONFIGURATION_API #include "../../../devapis/taint/phasar_taint_config_api.h" + #include struct Bar { diff --git a/tools/phasar-cli/Controller/AnalysisController.cpp b/tools/phasar-cli/Controller/AnalysisController.cpp index 44f25be72..a3013aa3e 100644 --- a/tools/phasar-cli/Controller/AnalysisController.cpp +++ b/tools/phasar-cli/Controller/AnalysisController.cpp @@ -10,7 +10,7 @@ #include "AnalysisController.h" #include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/Utils/NlohmannLogging.h" #include "AnalysisControllerInternal.h" diff --git a/tools/phasar-cli/phasar-cli.cpp b/tools/phasar-cli/phasar-cli.cpp index a6487aec4..c3addbb99 100644 --- a/tools/phasar-cli/phasar-cli.cpp +++ b/tools/phasar-cli/phasar-cli.cpp @@ -341,6 +341,8 @@ int main(int Argc, const char **Argv) { } if (LogOpt) { Logger::initializeStderrLogger(LogSeverityOpt); + } else if (!SilentOpt) { + Logger::initializeStderrLogger(SeverityLevel::ERROR); } for (const auto &LogCat : LogCategoriesOpt) { Logger::initializeStderrLogger(LogSeverityOpt, LogCat); diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedCFGTest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedCFGTest.cpp index 26c8f30d2..3753a403a 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedCFGTest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedCFGTest.cpp @@ -195,7 +195,7 @@ TEST(LLVMBasedCFGTest, HandleFieldLoadsArray) { const auto *F = IRDB.getFunctionDefinition("main"); const auto *Inst = getNthInstruction(F, 1); ASSERT_FALSE(Cfg.isFieldLoad(Inst)); - Inst = getNthInstruction(F, 6); + Inst = getNthInstruction(F, 5); ASSERT_TRUE(Cfg.isFieldLoad(Inst)); } @@ -205,7 +205,7 @@ TEST(LLVMBasedCFGTest, HandleFieldStoreArray) { const auto *F = IRDB.getFunctionDefinition("main"); const auto *Inst = getNthInstruction(F, 1); ASSERT_FALSE(Cfg.isFieldStore(Inst)); - Inst = getNthInstruction(F, 9); + Inst = getNthInstruction(F, 8); ASSERT_TRUE(Cfg.isFieldStore(Inst)); } diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGExportTest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGExportTest.cpp index 18f503fc3..4244a7c38 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGExportTest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGExportTest.cpp @@ -4,7 +4,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Passes/ValueAnnotationPass.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/IO.h" @@ -43,7 +43,7 @@ class LLVMBasedICFGExportTest : public ::testing::Test { nlohmann::json exportICFG(const std::string &TestFile, bool AsSrcCode = false) { LLVMProjectIRDB IRDB(PathToLLFiles + TestFile); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, nullptr, Soundness::Soundy, /*IncludeGlobals*/ false); @@ -183,7 +183,7 @@ class LLVMBasedICFGExportTest : public ::testing::Test { void verifyExportICFG(const llvm::Twine &TestFile, bool WithDebugOutput = false) { LLVMProjectIRDB IRDB(PathToLLFiles + TestFile); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, nullptr, Soundness::Soundy, /*IncludeGlobals*/ false); @@ -315,7 +315,7 @@ TEST_F(LLVMBasedICFGExportTest, ExportICFGSource02) { TEST_F(LLVMBasedICFGExportTest, ExportICFGSource03) { auto Results = exportICFG("exceptions/exceptions_01_cpp_dbg.ll", /*asSrcCode*/ true); - // llvm::errs() << Results.dump(4) << '\n'; + llvm::errs() << Results.dump(4) << '\n'; verifySourceCodeJSON(Results, readJson("exceptions/exceptions_01_cpp_icfg.json")); } diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGGlobCtorDtorTest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGGlobCtorDtorTest.cpp index 0977c8189..6e95f9c1a 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGGlobCtorDtorTest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGGlobCtorDtorTest.cpp @@ -15,7 +15,7 @@ #include "phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.h" #include "phasar/PhasarLLVM/Passes/ValueAnnotationPass.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" @@ -83,7 +83,7 @@ class LLVMBasedICFGGlobCtorDtorTest : public ::testing::Test { TEST_F(LLVMBasedICFGGlobCtorDtorTest, CtorTest) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_ctor_1_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); @@ -114,7 +114,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, CtorTest2) { ASSERT_FALSE(LinkerError); LLVMProjectIRDB IRDB(std::move(M1), /*DoPreprocessing*/ true); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); @@ -132,7 +132,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, CtorTest2) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, DtorTest1) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_dtor_1_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); @@ -167,7 +167,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, DtorTest1) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest1) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_lca_1_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); @@ -203,7 +203,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest1) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest2) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_lca_2_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); @@ -244,7 +244,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest2) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest3) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_lca_3_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); @@ -288,7 +288,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest3) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, DISABLED_LCATest4) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_lca_4_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG( &IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, @@ -321,7 +321,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, DISABLED_LCATest4) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest4_1) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_lca_4_1_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG( &IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, @@ -354,7 +354,7 @@ TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest4_1) { TEST_F(LLVMBasedICFGGlobCtorDtorTest, LCATest5) { LLVMProjectIRDB IRDB(PathToLLFiles + "globals_lca_5_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGTest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGTest.cpp index 249283fde..aa9b79ded 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGTest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGTest.cpp @@ -3,10 +3,9 @@ #include "phasar/Config/Configuration.h" #include "phasar/ControlFlow/CallGraphAnalysisType.h" #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h" -#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "llvm/Support/raw_ostream.h" @@ -28,7 +27,7 @@ template static auto makeSet(T &&Vec) { TEST(LLVMBasedICFGTest, StaticCallSite_1) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_1_c.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -49,7 +48,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_1) { TEST(LLVMBasedICFGTest, StaticCallSite_2a) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_2_c.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT, Soundness::Soundy, false); @@ -76,7 +75,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_2a) { TEST(LLVMBasedICFGTest, StaticCallSite_2b) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_2_c.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -110,7 +109,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_2b) { TEST(LLVMBasedICFGTest, VirtualCallSite_1) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_1_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -130,7 +129,7 @@ TEST(LLVMBasedICFGTest, VirtualCallSite_1) { TEST(LLVMBasedICFGTest, FunctionPointer_1) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/function_pointer_1_c.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -149,7 +148,7 @@ TEST(LLVMBasedICFGTest, FunctionPointer_1) { TEST(LLVMBasedICFGTest, StaticCallSite_3) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_3_c.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *Factorial = IRDB.getFunctionDefinition("factorial"); @@ -169,7 +168,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_3) { TEST(LLVMBasedICFGTest, StaticCallSite_4) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_4_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -202,7 +201,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_4) { TEST(LLVMBasedICFGTest, StaticCallSite_5) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_5_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -225,7 +224,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_5) { TEST(LLVMBasedICFGTest, StaticCallSite_6) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_6_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -251,7 +250,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_6) { TEST(LLVMBasedICFGTest, StaticCallSite_7) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_7_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *Main = IRDB.getFunctionDefinition("main"); @@ -275,7 +274,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_7) { TEST(LLVMBasedICFGTest, StaticCallSite_8) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_8_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -299,7 +298,7 @@ TEST(LLVMBasedICFGTest, StaticCallSite_8) { TEST(LLVMBasedICFGTest, GlobalCtorDtor_1) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/global_ctor_dtor_1_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT, Soundness::Soundy, true); @@ -326,7 +325,7 @@ TEST(LLVMBasedICFGTest, GlobalCtorDtor_1) { TEST(LLVMBasedICFGTest, GlobalCtorDtor_2) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/global_ctor_dtor_2_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT, Soundness::Soundy, true); @@ -350,7 +349,7 @@ TEST(LLVMBasedICFGTest, GlobalCtorDtor_2) { TEST(LLVMBasedICFGTest, GlobalCtorDtor_3) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/global_ctor_dtor_3_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT, Soundness::Soundy, true); @@ -371,7 +370,7 @@ TEST(LLVMBasedICFGTest, GlobalCtorDtor_3) { TEST(LLVMBasedICFGTest, GlobalCtorDtor_4) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/global_ctor_dtor_4_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT, Soundness::Soundy, true); diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_CHATest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_CHATest.cpp index b062bdd4c..832836639 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_CHATest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_CHATest.cpp @@ -3,7 +3,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "TestConfig.h" @@ -17,7 +17,7 @@ using namespace psr; TEST(LLVMBasedICFG_CHATest, StaticCallSite_1) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_1_c.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -39,7 +39,7 @@ TEST(LLVMBasedICFG_CHATest, StaticCallSite_1) { TEST(LLVMBasedICFG_CHATest, VirtualCallSite_2) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_2_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -61,7 +61,7 @@ TEST(LLVMBasedICFG_CHATest, VirtualCallSite_2) { TEST(LLVMBasedICFG_CHATest, VirtualCallSite_9) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_9_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -88,7 +88,7 @@ TEST(LLVMBasedICFG_CHATest, VirtualCallSite_9) { TEST(LLVMBasedICFG_CHATest, VirtualCallSite_7) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_7_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::CHA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_DTATest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_DTATest.cpp index 07f5b80b9..f66e02430 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_DTATest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_DTATest.cpp @@ -3,19 +3,20 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "TestConfig.h" #include "gtest/gtest.h" -using namespace std; using namespace psr; TEST(LLVMBasedICFG_DTATest, VirtualCallSite_5) { + GTEST_SKIP() << "Requires typed pointers!"; LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_5_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::DTA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -41,9 +42,10 @@ TEST(LLVMBasedICFG_DTATest, VirtualCallSite_5) { } TEST(LLVMBasedICFG_DTATest, VirtualCallSite_6) { + GTEST_SKIP() << "Requires typed pointers!"; LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_6_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::DTA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_OTFTest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_OTFTest.cpp index ba4df9fc7..bb6c8da5d 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_OTFTest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_OTFTest.cpp @@ -5,6 +5,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" @@ -19,8 +20,8 @@ using namespace psr; TEST(LLVMBasedICFG_OTFTest, VirtualCallSite_7) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + - "call_graphs/virtual_call_7_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + "call_graphs/virtual_call_7_cpp_dbg.ll"); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB, false); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT); @@ -32,17 +33,18 @@ TEST(LLVMBasedICFG_OTFTest, VirtualCallSite_7) { ASSERT_TRUE(VFuncA); ASSERT_TRUE(VFuncB); - const auto *CallToAFunc = getNthInstruction(F, 19); + const auto *CallToAFunc = getNthInstruction(F, 17); ASSERT_TRUE(ICFG.isVirtualFunctionCall(CallToAFunc)); const auto &AsCallees = ICFG.getCalleesOfCallAt(CallToAFunc); ASSERT_EQ(AsCallees.size(), 2U); ASSERT_TRUE(llvm::is_contained(AsCallees, VFuncA)); ASSERT_TRUE(llvm::is_contained(ICFG.getCallersOf(VFuncA), CallToAFunc)); - const auto *CallToBFunc = getNthInstruction(F, 25); + const auto *CallToBFunc = getNthInstruction(F, 22); ASSERT_TRUE(ICFG.isVirtualFunctionCall(CallToBFunc)); const auto &BsCallees = ICFG.getCalleesOfCallAt(CallToBFunc); ASSERT_EQ(BsCallees.size(), 2U); + ASSERT_TRUE(llvm::is_contained(BsCallees, VFuncB)); ASSERT_TRUE(llvm::is_contained(ICFG.getCallersOf(VFuncB), CallToBFunc)); } @@ -50,7 +52,7 @@ TEST(LLVMBasedICFG_OTFTest, VirtualCallSite_7) { // TEST(LLVMBasedICFG_OTFTest, VirtualCallSite_8) { // ProjectIRDB IRDB({pathToLLFiles + "call_graphs/virtual_call_8_cpp.ll"}, // IRDBOptions::WPA); -// LLVMTypeHierarchy TH(IRDB); +// DIBasedTypeHierarchy TH(IRDB); // LLVMAliasInfo PT(IRDB); // LLVMBasedICFG ICFG(IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT); // const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -70,15 +72,15 @@ TEST(LLVMBasedICFG_OTFTest, VirtualCallSite_7) { TEST(LLVMBasedICFG_OTFTest, FunctionPtrCall_2) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + - "call_graphs/function_pointer_2_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + "call_graphs/function_pointer_2_cpp_dbg.ll"); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB, false); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT); const llvm::Function *Main = IRDB.getFunctionDefinition("main"); const llvm::Function *Bar = IRDB.getFunctionDefinition("_Z3barv"); - const auto *FPtrCall = getNthInstruction(Main, 7); + const auto *FPtrCall = getNthInstruction(Main, 9); const auto &Callees = ICFG.getCalleesOfCallAt(FPtrCall); auto printCallees // NOLINT @@ -108,15 +110,16 @@ TEST(LLVMBasedICFG_OTFTest, FunctionPtrCall_2) { TEST(LLVMBasedICFG_OTFTest, FunctionPtrCall_3) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + - "call_graphs/function_pointer_3_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + "call_graphs/function_pointer_3_cpp_dbg.ll"); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB, false); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT); const llvm::Function *Main = IRDB.getFunctionDefinition("main"); const llvm::Function *Foo = IRDB.getFunctionDefinition("_Z3foov"); - const auto *FPtrCall = getNthInstruction(Main, 8); + const auto *FPtrCall = getNthInstruction(Main, 10); + const auto &Callees = ICFG.getCalleesOfCallAt(FPtrCall); ASSERT_EQ(Callees.size(), 1U); diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_RTATest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_RTATest.cpp index 7503bca44..c807f5512 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_RTATest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_RTATest.cpp @@ -3,7 +3,7 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "TestConfig.h" @@ -15,7 +15,7 @@ using namespace psr; TEST(LLVMBasedICFG_RTATest, VirtualCallSite_9) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_9_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::RTA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -41,7 +41,7 @@ TEST(LLVMBasedICFG_RTATest, VirtualCallSite_9) { TEST(LLVMBasedICFG_RTATest, VirtualCallSite_3) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/virtual_call_3_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::RTA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); @@ -61,7 +61,7 @@ TEST(LLVMBasedICFG_RTATest, VirtualCallSite_3) { TEST(LLVMBasedICFG_RTATest, StaticCallSite_13) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "call_graphs/static_callsite_13_cpp.ll"); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMAliasSet PT(&IRDB); LLVMBasedICFG ICFG(&IRDB, CallGraphAnalysisType::RTA, {"main"}, &TH, &PT); const llvm::Function *F = IRDB.getFunctionDefinition("main"); diff --git a/unittests/PhasarLLVM/ControlFlow/LLVMVFTableProviderTest.cpp b/unittests/PhasarLLVM/ControlFlow/LLVMVFTableProviderTest.cpp index 1cd66805e..54ef8b0d7 100644 --- a/unittests/PhasarLLVM/ControlFlow/LLVMVFTableProviderTest.cpp +++ b/unittests/PhasarLLVM/ControlFlow/LLVMVFTableProviderTest.cpp @@ -2,11 +2,15 @@ #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h" +#include "phasar/PhasarLLVM/Utils/LLVMIRToSrc.h" #include "llvm/ADT/StringRef.h" #include "llvm/Demangle/Demangle.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" #include "TestConfig.h" #include "gtest/gtest.h" @@ -17,12 +21,28 @@ namespace { using llvm::demangle; -static const llvm::StructType *getType(const LLVMProjectIRDB &IRDB, - llvm::StringRef Name) { +static const llvm::DIType *getType(const LLVMProjectIRDB &IRDB, + llvm::StringRef Name) { // TODO: Optimize - for (const auto *Ty : IRDB.getModule()->getIdentifiedStructTypes()) { - if (Ty->getName() == Name) { - return Ty; + for (const auto *Instr : IRDB.getAllInstructions()) { + if (const auto *Val = llvm::dyn_cast(Instr)) { + if (const auto *DILocVal = getDILocalVariable(Val)) { + // case: is DIDerivedType + if (const auto *DerivedTy = + llvm::dyn_cast(DILocVal->getType())) { + if (const auto *DITy = DerivedTy->getBaseType()) { + if (DITy->getName() == Name) { + return DITy; + } + } + } + // case: isn't DIDerivedType + if (const auto *DITy = DILocVal->getType()) { + if (DITy->getName() == Name) { + return DITy; + } + } + } } } return nullptr; @@ -32,137 +52,147 @@ static const llvm::StructType *getType(const LLVMProjectIRDB &IRDB, TEST(VTableTest, VTableConstruction_01) { LLVMProjectIRDB IRDB({unittest::PathToLLTestFiles + - "type_hierarchies/type_hierarchy_1_cpp.ll"}); + "type_hierarchies/type_hierarchy_1_cpp_dbg.ll"}); LLVMVFTableProvider TH(IRDB); // TODO } TEST(VTableTest, VTableConstruction_02) { LLVMProjectIRDB IRDB({unittest::PathToLLTestFiles + - "type_hierarchies/type_hierarchy_7_cpp.ll"}); + "type_hierarchies/type_hierarchy_7_cpp_dbg.ll"}); LLVMVFTableProvider TH(IRDB); // TODO } TEST(VTableTest, VTableConstruction_03) { LLVMProjectIRDB IRDB({unittest::PathToLLTestFiles + - "type_hierarchies/type_hierarchy_8_cpp.ll"}); + "type_hierarchies/type_hierarchy_8_cpp_dbg.ll"}); LLVMVFTableProvider TH(IRDB); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "struct.Base"))); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "struct.Child"))); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Base"))); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Child"))); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Base")) + llvm::outs() << "AllFuncs:\n"; + for (const auto *CurrFunc : + TH.getVFTableOrNull(getType(IRDB, "Base"))->getAllFunctions()) { + llvm::outs() << CurrFunc << "\n"; + } + + llvm::outs() << "getFunction(0)\n" + << TH.getVFTableOrNull(getType(IRDB, "Base"))->getFunction(0) + << "\n"; + + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Base")) ->getFunction(0) ->getName() .str()), "Base::foo()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Base")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Base")) ->getFunction(1) ->getName() .str()), "Base::bar()"); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "struct.Base"))->size(), 2U); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Base"))->size(), 2U); + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(0) ->getName() .str()), "Child::foo()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(1) ->getName() .str()), "Base::bar()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(2) ->getName() .str()), "Child::baz()"); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "struct.Child"))->size(), 3U); + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Child"))->size(), 3U); } TEST(VTableTest, VTableConstruction_04) { LLVMProjectIRDB IRDB({unittest::PathToLLTestFiles + - "type_hierarchies/type_hierarchy_9_cpp.ll"}); + "type_hierarchies/type_hierarchy_9_cpp_dbg.ll"}); LLVMVFTableProvider TH(IRDB); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "struct.Base"))); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "struct.Child"))); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Base"))); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Child"))); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Base")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Base")) ->getFunction(0) ->getName() .str()), "Base::foo()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Base")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Base")) ->getFunction(1) ->getName() .str()), "Base::bar()"); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "struct.Base"))->size(), 2U); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Base"))->size(), 2U); + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(0) ->getName() .str()), "Child::foo()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(1) ->getName() .str()), "Base::bar()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(2) ->getName() .str()), "Child::baz()"); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "struct.Child"))->size(), 3U); + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Child"))->size(), 3U); } TEST(VTableTest, VTableConstruction_05) { LLVMProjectIRDB IRDB({unittest::PathToLLTestFiles + - "type_hierarchies/type_hierarchy_10_cpp.ll"}); + "type_hierarchies/type_hierarchy_10_cpp_dbg.ll"}); LLVMVFTableProvider TH(IRDB); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "struct.Base"))); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "struct.Child"))); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Child"))); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Child"))); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Base")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Base")) ->getFunction(0) ->getName() .str()), "__cxa_pure_virtual"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Base")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Base")) ->getFunction(1) ->getName() .str()), "Base::bar()"); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "struct.Base"))->size(), 2U); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Base"))->size(), 2U); + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(0) ->getName() .str()), "Child::foo()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(1) ->getName() .str()), "Base::bar()"); - EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "struct.Child")) + EXPECT_EQ(demangle(TH.getVFTableOrNull(getType(IRDB, "Child")) ->getFunction(2) ->getName() .str()), "Child::baz()"); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "struct.Child"))->size(), 3U); + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Child"))->size(), 3U); } TEST(VTableTest, VTableConstruction_6) { LLVMProjectIRDB IRDB({unittest::PathToLLTestFiles + - "type_hierarchies/type_hierarchy_14_cpp.ll"}); + "type_hierarchies/type_hierarchy_14_cpp_dbg.ll"}); LLVMVFTableProvider TH(IRDB); - ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "class.Base"))); - EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "class.Base"))->size(), 3U); + ASSERT_TRUE(TH.hasVFTable(getType(IRDB, "Base"))); + EXPECT_EQ(TH.getVFTableOrNull(getType(IRDB, "Base"))->size(), 3U); } } // namespace diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysisTest.cpp b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysisTest.cpp index 806cb58e2..5c3395b6d 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysisTest.cpp +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysisTest.cpp @@ -57,7 +57,7 @@ class IDETaintAnalysisTest : public ::testing::Test { void doAnalysis( const llvm::Twine &IRFile, const map> &GroundTruth, std::variant Config, - bool DumpResults = false) { + bool DumpResults = true) { HelperAnalyses HA(IRFile, EntryPoints); auto TC = @@ -140,7 +140,7 @@ TEST_F(IDETaintAnalysisTest, XTaint01_Json) { TEST_F(IDETaintAnalysisTest, XTaint01) { map> Gt; - Gt[15] = {"14"}; + Gt[13] = {"12"}; doAnalysis({PathToLLFiles + "xtaint01_cpp.ll"}, Gt, std::monostate{}); } @@ -148,14 +148,14 @@ TEST_F(IDETaintAnalysisTest, XTaint01) { TEST_F(IDETaintAnalysisTest, XTaint02) { map> Gt; - Gt[20] = {"19"}; + Gt[18] = {"17"}; doAnalysis({PathToLLFiles + "xtaint02_cpp.ll"}, Gt, std::monostate{}, true); } TEST_F(IDETaintAnalysisTest, XTaint03) { map> Gt; - Gt[23] = {"22"}; + Gt[21] = {"20"}; doAnalysis({PathToLLFiles + "xtaint03_cpp.ll"}, Gt, std::monostate{}); } @@ -163,7 +163,7 @@ TEST_F(IDETaintAnalysisTest, XTaint03) { TEST_F(IDETaintAnalysisTest, XTaint04) { map> Gt; - Gt[17] = {"16"}; + Gt[16] = {"15"}; doAnalysis({PathToLLFiles + "xtaint04_cpp.ll"}, Gt, std::monostate{}); } @@ -200,7 +200,7 @@ TEST_F(IDETaintAnalysisTest, DISABLED_XTaint08) { TEST_F(IDETaintAnalysisTest, XTaint09_1) { map> Gt; - Gt[27] = {"26"}; + Gt[25] = {"24"}; doAnalysis({PathToLLFiles + "xtaint09_1_cpp.ll"}, Gt, std::monostate{}); } @@ -208,7 +208,7 @@ TEST_F(IDETaintAnalysisTest, XTaint09_1) { TEST_F(IDETaintAnalysisTest, XTaint09) { map> Gt; - Gt[34] = {"33"}; + Gt[33] = {"32"}; doAnalysis({PathToLLFiles + "xtaint09_cpp.ll"}, Gt, std::monostate{}); } @@ -241,7 +241,7 @@ TEST_F(IDETaintAnalysisTest, XTaint12) { // We sanitize an alias - since we don't have must-alias relations, we cannot // kill aliases at all - Gt[30] = {"29"}; + Gt[28] = {"27"}; doAnalysis({PathToLLFiles + "xtaint12_cpp.ll"}, Gt, std::monostate{}); } @@ -249,7 +249,7 @@ TEST_F(IDETaintAnalysisTest, XTaint12) { TEST_F(IDETaintAnalysisTest, XTaint13) { map> Gt; - Gt[32] = {"31"}; + Gt[30] = {"29"}; doAnalysis({PathToLLFiles + "xtaint13_cpp.ll"}, Gt, std::monostate{}); } @@ -257,7 +257,7 @@ TEST_F(IDETaintAnalysisTest, XTaint13) { TEST_F(IDETaintAnalysisTest, XTaint14) { map> Gt; - Gt[35] = {"34"}; + Gt[33] = {"32"}; doAnalysis({PathToLLFiles + "xtaint14_cpp.ll"}, Gt, std::monostate{}); } @@ -275,7 +275,7 @@ TEST_F(IDETaintAnalysisTest, DISABLED_XTaint15) { TEST_F(IDETaintAnalysisTest, XTaint16) { map> Gt; - Gt[26] = {"25"}; + Gt[24] = {"23"}; doAnalysis({PathToLLFiles + "xtaint16_cpp.ll"}, Gt, std::monostate{}); } @@ -283,7 +283,7 @@ TEST_F(IDETaintAnalysisTest, XTaint16) { TEST_F(IDETaintAnalysisTest, XTaint17) { map> Gt; - Gt[29] = {"28"}; + Gt[27] = {"26"}; doAnalysis({PathToLLFiles + "xtaint17_cpp.ll"}, Gt, std::monostate{}); } @@ -309,8 +309,8 @@ PHASAR_SKIP_TEST(TEST_F(IDETaintAnalysisTest, XTaint19) { TEST_F(IDETaintAnalysisTest, XTaint20) { map> Gt; - Gt[25] = {"17"}; - Gt[27] = {"26"}; + Gt[22] = {"14"}; + Gt[24] = {"23"}; doAnalysis({PathToLLFiles + "xtaint20_cpp.ll"}, Gt, std::monostate{}); } diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCATest.cpp b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCATest.cpp index 17a74b610..b3381ff3d 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCATest.cpp +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCATest.cpp @@ -129,9 +129,10 @@ TEST_F(IDEGeneralizedLCATest, StringTestCpp) { std::vector GroundTruth; const auto *LastMainInstruction = getLastInstructionOf(HA->getProjectIRDB().getFunction("main")); - GroundTruth.push_back({{EdgeValue("Hello, World")}, - 3, - std::stoi(getMetaDataID(LastMainInstruction))}); + GroundTruth.push_back( + {{EdgeValue("Hello, World")}, + 3, + (unsigned int)std::stoi(getMetaDataID(LastMainInstruction))}); compareResults(GroundTruth); } diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysisTest.cpp b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysisTest.cpp index d0ca110ab..a1368dc25 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysisTest.cpp +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysisTest.cpp @@ -143,11 +143,11 @@ TEST_F(IDEInstInteractionAnalysisTest, FieldSensArrayConstruction_01) { llvm::outs() << "Instruction to create flow fact from: " << *Inst << '\n'; auto FlowFact = IDEIIAFlowFact::create(Inst); llvm::outs() << FlowFact << '\n'; - Inst = getNthInstruction(Main, 14); + Inst = getNthInstruction(Main, 13); llvm::outs() << "Instruction to create flow fact from: " << *Inst << '\n'; FlowFact = IDEIIAFlowFact::create(Inst); llvm::outs() << FlowFact << '\n'; - Inst = getNthInstruction(Main, 17); + Inst = getNthInstruction(Main, 16); llvm::outs() << "Instruction to create flow fact from: " << *Inst << '\n'; FlowFact = IDEIIAFlowFact::create(Inst); llvm::outs() << FlowFact << '\n'; @@ -240,6 +240,7 @@ TEST_F(IDEInstInteractionAnalysisTest, FieldSensStructConstruction_02) { TEST_F(IDEInstInteractionAnalysisTest, ArrayEquality_01) { initializeIR("array_01_cpp.ll"); + const auto *Main = IRDB->getFunction("main"); const auto *Inst = getNthInstruction(Main, 2); auto FlowFact = IDEIIAFlowFact::create(Inst); @@ -247,19 +248,20 @@ TEST_F(IDEInstInteractionAnalysisTest, ArrayEquality_01) { Inst = getNthInstruction(Main, 4); FlowFact = IDEIIAFlowFact::create(Inst); - Inst = getNthInstruction(Main, 14); + Inst = getNthInstruction(Main, 13); auto OtherFlowFact = IDEIIAFlowFact::create(Inst); ASSERT_NE(FlowFact, OtherFlowFact); - Inst = getNthInstruction(Main, 14); + Inst = getNthInstruction(Main, 13); + FlowFact = IDEIIAFlowFact::create(Inst); - Inst = getNthInstruction(Main, 19); + Inst = getNthInstruction(Main, 18); OtherFlowFact = IDEIIAFlowFact::create(Inst); ASSERT_EQ(FlowFact, OtherFlowFact); - Inst = getNthInstruction(Main, 17); + Inst = getNthInstruction(Main, 16); FlowFact = IDEIIAFlowFact::create(Inst); - Inst = getNthInstruction(Main, 22); + Inst = getNthInstruction(Main, 21); OtherFlowFact = IDEIIAFlowFact::create(Inst); ASSERT_EQ(FlowFact, OtherFlowFact); } @@ -395,8 +397,10 @@ TEST_F(IDEInstInteractionAnalysisTest, StructEquality_02) { ASSERT_EQ(FlowFact, OtherFlowFact); Inst = getNthInstruction(Main, 6); + llvm::outs() << "Instruction to create flow fact from: " << *Inst << '\n'; FlowFact = IDEIIAFlowFact::create(Inst); Inst = getNthInstruction(Main, 9); + llvm::outs() << "Instruction to create flow fact from 2: " << *Inst << '\n'; OtherFlowFact = IDEIIAFlowFact::create(Inst); ASSERT_NE(FlowFact, OtherFlowFact); } @@ -844,13 +848,13 @@ TEST_F(IDEInstInteractionAnalysisTest, HandleHeapTest_01) { std::set GroundTruth; GroundTruth.emplace( std::tuple>( - "main", 19, "retval", {"3"})); + "main", 17, "retval", {"3"})); GroundTruth.emplace( std::tuple>( - "main", 19, "i", {"6", "7"})); + "main", 17, "i", {"5", "6"})); GroundTruth.emplace( std::tuple>( - "main", 19, "j", {"6", "7", "8", "10", "9"})); + "main", 17, "j", {"5", "6", "7", "8", "9"})); doAnalysisAndCompareResults("heap_01_cpp.ll", {"main"}, GroundTruth, false); } diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSConstAnalysisTest.cpp b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSConstAnalysisTest.cpp index 77f858c30..b36430c3c 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSConstAnalysisTest.cpp +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSConstAnalysisTest.cpp @@ -175,7 +175,7 @@ TEST_F(IFDSConstAnalysisTest, HandlePointerTest_04) { initialize({PathToLlFiles + "pointer/pointer_04_cpp_m2r_dbg.ll"}); IFDSSolver Llvmconstsolver(*Constproblem, &HA->getICFG()); Llvmconstsolver.solve(); - compareResults({4}, Llvmconstsolver); + compareResults({3}, Llvmconstsolver); } /* ============== GLOBAL TESTS ============== */ diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSTaintAnalysisTest.cpp b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSTaintAnalysisTest.cpp index f01c12b96..e050acc5d 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSTaintAnalysisTest.cpp +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSTaintAnalysisTest.cpp @@ -193,7 +193,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_01) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[15] = set{"14"}; + GroundTruth[14] = set{"13"}; compareResults(GroundTruth); } @@ -203,7 +203,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_01_m2r) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[6] = set{"0"}; + GroundTruth[5] = set{"0"}; compareResults(GroundTruth); } @@ -213,7 +213,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_02) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[17] = set{"16"}; + GroundTruth[16] = set{"15"}; compareResults(GroundTruth); } @@ -224,7 +224,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_03) { TaintSolver.solve(); map> GroundTruth; GroundTruth[11] = set{"10"}; - GroundTruth[21] = set{"20"}; + GroundTruth[20] = set{"19"}; compareResults(GroundTruth); } @@ -234,7 +234,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_04) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[33] = set{"32"}; + GroundTruth[32] = set{"31"}; compareResults(GroundTruth); } @@ -245,7 +245,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_05) { TaintSolver.solve(); map> GroundTruth; - GroundTruth[33] = set{"32"}; + GroundTruth[32] = set{"31"}; compareResults(GroundTruth); } @@ -255,7 +255,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_06) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[15] = set{"14"}; + GroundTruth[14] = set{"13"}; compareResults(GroundTruth); } @@ -265,7 +265,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_07) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[31] = set{"30"}; + GroundTruth[30] = set{"29"}; compareResults(GroundTruth); } @@ -275,7 +275,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_08) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[33] = set{"32"}; + GroundTruth[32] = set{"31"}; compareResults(GroundTruth); } @@ -285,7 +285,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_09) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[64] = set{"63"}; + GroundTruth[62] = set{"61"}; compareResults(GroundTruth); } @@ -295,7 +295,7 @@ TEST_F(IFDSTaintAnalysisTest, TaintTest_ExceptionHandling_10) { IFDSSolver TaintSolver(*TaintProblem, &HA->getICFG()); TaintSolver.solve(); map> GroundTruth; - GroundTruth[62] = set{"61"}; + GroundTruth[60] = set{"59"}; compareResults(GroundTruth); } diff --git a/unittests/PhasarLLVM/DataFlow/PathSensitivity/PathTracingTest.cpp b/unittests/PhasarLLVM/DataFlow/PathSensitivity/PathTracingTest.cpp index 0194d0eea..76261020e 100644 --- a/unittests/PhasarLLVM/DataFlow/PathSensitivity/PathTracingTest.cpp +++ b/unittests/PhasarLLVM/DataFlow/PathSensitivity/PathTracingTest.cpp @@ -11,7 +11,7 @@ #include "phasar/PhasarLLVM/Passes/ValueAnnotationPass.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" #include "phasar/PhasarLLVM/TaintConfig/LLVMTaintConfig.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/AdjacencyList.h" #include "phasar/Utils/DFAMinimizer.h" @@ -81,7 +81,7 @@ class PathTracingTest : public ::testing::Test { psr::FlowPathSequence doAnalysis(const std::string &LlvmFilePath, bool PrintDump = false) { IRDB = std::make_unique(PathToLlFiles + LlvmFilePath); - psr::LLVMTypeHierarchy TH(*IRDB); + psr::DIBasedTypeHierarchy TH(*IRDB); psr::LLVMAliasSet PT(IRDB.get()); psr::LLVMBasedICFG ICFG(IRDB.get(), psr::CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, psr::Soundness::Soundy, @@ -113,7 +113,7 @@ class PathTracingTest : public ::testing::Test { doLambdaAnalysis(const std::string &LlvmFilePath, size_t MaxDAGDepth = SIZE_MAX) { IRDB = std::make_unique(PathToLlFiles + LlvmFilePath); - psr::LLVMTypeHierarchy TH(*IRDB); + psr::DIBasedTypeHierarchy TH(*IRDB); psr::LLVMAliasSet PT(IRDB.get()); psr::LLVMBasedICFG ICFG(IRDB.get(), psr::CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, psr::Soundness::Soundy, @@ -536,9 +536,9 @@ TEST_F(PathTracingTest, Handle_Inter_11) { auto PathsVec = doAnalysis("inter_11_cpp.ll"); // Note: The alias analysis is strong enough to see that Three::assignValue // can never be called - comparePaths(PathsVec, {{8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 27, 28, 29, - 30, 31, 35, 36, 37, 38, 39, 40, 32, 33, 34, 18, 19, - 20, 21, 22, 23, 24, 25, 41, 44, 46, 47, 48, 26}}); + comparePaths(PathsVec, {{8, 9, 10, 11, 12, 13, 14, 15, 16, 24, 25, + 26, 27, 30, 31, 32, 33, 34, 28, 29, 17, 18, + 19, 20, 21, 22, 35, 38, 40, 41, 42, 23}}); } TEST_F(PathTracingTest, Lambda_Inter_11) { @@ -547,46 +547,63 @@ TEST_F(PathTracingTest, Lambda_Inter_11) { auto PathsVec = doLambdaAnalysis("inter_11_cpp.ll"); // Note: The alias analysis is strong enough to see that Three::assignValue // can never be called - comparePaths(PathsVec, - {{8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 27, 28, 29, 30, - 31, 35, 36, 37, 38, 39, 40, 32, 33, 34, 18, 19, 20, 21, - 22, 23, 24, 25, 41, 42, 43, 44, 45, 46, 47, 48, 26}}); + comparePaths(PathsVec, {{8, 9, 10, 11, 12, 13, 14, 15, 16, 24, 25, 26, + 27, 30, 31, 32, 33, 34, 28, 29, 17, 18, 19, 20, + 21, 22, 35, 36, 37, 38, 39, 40, 41, 42, 23}}); } TEST_F(PathTracingTest, Handle_Inter_12) { auto PathsVec = doAnalysis("inter_12_cpp.ll"); comparePaths( PathsVec, - {{11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, - 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 32, - 33, 34, 52, 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, - 59, 35, 36, 37, 38, 39, 40, 41, 42, 79, 82, 84, 85, 86, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, - 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 32, - 33, 34, 52, 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, - 59, 35, 36, 37, 38, 39, 40, 41, 42, 109, 112, 114, 115, 116, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, 60, 61, - 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 72, 73, 74, 75, 66, 67, 68, 69, 70, 87, 88, 89, 90, 71, 76, 77, 78, - 31, 32, 33, 34, 52, 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, - 59, 35, 36, 37, 38, 39, 40, 41, 42, 79, 82, 84, 85, 86, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, 60, 61, - 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 72, 73, 74, 75, 66, 67, 68, 69, 70, 87, 88, 89, 90, 71, 76, 77, 78, - 31, 32, 33, 34, 52, 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, - 59, 35, 36, 37, 38, 39, 40, 41, 42, 109, 112, 114, 115, 116, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, - 48, 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 102, 103, 104, 105, 96, 97, 98, 99, - 100, 87, 88, 89, 90, 101, 106, 107, 108, 31, 32, 33, 34, 52, - 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, - 36, 37, 38, 39, 40, 41, 42, 79, 82, 84, 85, 86, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, - 48, 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 102, 103, 104, 105, 96, 97, 98, 99, - 100, 87, 88, 89, 90, 101, 106, 107, 108, 31, 32, 33, 34, 52, - 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, - 36, 37, 38, 39, 40, 41, 42, 109, 112, 114, 115, 116, 43}}); + {{11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, + 54, 42, 43, 20, 21, 22, 23, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 66, 69, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, + 54, 42, 43, 20, 21, 22, 23, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 94, 97, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, + 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 74, 75, + 76, 77, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, + 49, 31, 32, 33, 34, 35, 36, 66, 69, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, + 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 74, 75, + 76, 77, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, + 49, 31, 32, 33, 34, 35, 36, 94, 97, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, + 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 86, + 74, 75, 76, 77, 87, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 66, 69, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, + 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 86, + 74, 75, 76, 77, 87, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 94, 97, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, + 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 55, 56, 57, 58, + 74, 75, 76, 77, 59, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 66, 69, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, + 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 55, 56, 57, 58, + 74, 75, 76, 77, 59, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 94, 97, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, 54, + 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 88, 89, 90, 91, 83, 84, 85, 86, + 74, 75, 76, 77, 87, 92, 93, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 66, 69, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, + 51, 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, + 88, 89, 90, 91, 83, 84, 85, 86, 74, 75, 76, 77, 87, 92, + 93, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, + 49, 31, 32, 33, 34, 35, 36, 94, 97, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, 54, + 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 60, 61, 62, 63, 55, 56, 57, 58, + 74, 75, 76, 77, 59, 64, 65, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 66, 69, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, + 51, 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, + 60, 61, 62, 63, 55, 56, 57, 58, 74, 75, 76, 77, 59, 64, + 65, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, + 49, 31, 32, 33, 34, 35, 36, 94, 97, 99, 100, 101, 37}}); } TEST_F(PathTracingTest, Lambda_Inter_12) { @@ -595,41 +612,56 @@ TEST_F(PathTracingTest, Lambda_Inter_12) { auto PathsVec = doLambdaAnalysis("inter_12_cpp.ll"); comparePaths( PathsVec, - { - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, - 47, 48, 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, - 23, 24, 25, 32, 33, 34, 52, 53, 54, 55, 56, 60, 61, - 62, 63, 64, 65, 57, 58, 59, 35, 36, 37, 38, 39, 40, - 41, 42, 109, 110, 111, 112, 113, 114, 115, 116, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, - 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 72, 73, 74, 75, 66, 67, 68, 69, 70, 87, 88, - 89, 90, 71, 76, 77, 78, 31, 32, 33, 34, 52, 53, 54, 55, 56, - 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, 36, 37, 38, 39, 40, - 41, 42, 79, 80, 81, 82, 83, 84, 85, 86, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, - 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 72, 73, 74, 75, 66, 67, 68, 69, 70, 87, 88, - 89, 90, 71, 76, 77, 78, 31, 32, 33, 34, 52, 53, 54, 55, 56, - 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, 36, 37, 38, 39, 40, - 41, 42, 109, 110, 111, 112, 113, 114, 115, 116, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, - 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 102, 103, 104, 105, 96, 97, 98, 99, 100, 87, 88, - 89, 90, 101, 106, 107, 108, 31, 32, 33, 34, 52, 53, 54, 55, 56, - 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, 36, 37, 38, 39, 40, - 41, 42, 79, 80, 81, 82, 83, 84, 85, 86, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, - 60, 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 102, 103, 104, 105, 96, 97, 98, 99, 100, 87, 88, - 89, 90, 101, 106, 107, 108, 31, 32, 33, 34, 52, 53, 54, 55, 56, - 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, 36, 37, 38, 39, 40, - 41, 42, 109, 110, 111, 112, 113, 114, 115, 116, 43}, - {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 44, 45, 46, 47, 48, 60, - 61, 62, 63, 64, 65, 49, 50, 51, 21, 22, 23, 24, 25, 32, 33, 34, - 52, 53, 54, 55, 56, 60, 61, 62, 63, 64, 65, 57, 58, 59, 35, 36, - 37, 38, 39, 40, 41, 42, 79, 80, 81, 82, 83, 84, 85, 86, 43}, - }); + {{11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, + 50, 51, 52, 53, 54, 42, 43, 20, 21, 22, 23, 29, 30, + 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, 31, 32, + 33, 34, 35, 36, 94, 95, 96, 97, 98, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, 54, + 42, 43, 20, 21, 22, 23, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, + 49, 31, 32, 33, 34, 35, 36, 66, 67, 68, 69, 70, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, + 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 74, 75, 76, 77, + 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, 31, 32, + 33, 34, 35, 36, 94, 95, 96, 97, 98, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, + 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 74, 75, 76, 77, + 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, 31, 32, + 33, 34, 35, 36, 66, 67, 68, 69, 70, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, + 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 55, 56, 57, 58, 74, 75, + 76, 77, 59, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, + 31, 32, 33, 34, 35, 36, 94, 95, 96, 97, 98, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, + 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 55, 56, 57, 58, 74, 75, + 76, 77, 59, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, + 31, 32, 33, 34, 35, 36, 66, 67, 68, 69, 70, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, + 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 86, 74, 75, + 76, 77, 87, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, + 31, 32, 33, 34, 35, 36, 94, 95, 96, 97, 98, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, + 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 86, 74, 75, + 76, 77, 87, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, + 31, 32, 33, 34, 35, 36, 66, 67, 68, 69, 70, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, + 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 88, 89, + 90, 91, 83, 84, 85, 86, 74, 75, 76, 77, 87, 92, 93, 28, 29, + 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, 31, 32, 33, + 34, 35, 36, 94, 95, 96, 97, 98, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, 52, 53, 54, + 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 88, 89, 90, 91, 83, 84, 85, 86, + 74, 75, 76, 77, 87, 92, 93, 28, 29, 30, 44, 45, 46, 47, 50, 51, 52, 53, + 54, 48, 49, 31, 32, 33, 34, 35, 36, 66, 67, 68, 69, 70, 71, 72, 73, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, + 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 60, 61, + 62, 63, 55, 56, 57, 58, 74, 75, 76, 77, 59, 64, 65, 28, 29, + 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, 31, 32, 33, + 34, 35, 36, 94, 95, 96, 97, 98, 99, 100, 101, 37}, + {11, 12, 13, 14, 15, 16, 17, 18, 19, 38, 39, 40, 41, 50, 51, + 52, 53, 54, 42, 43, 20, 21, 22, 23, 24, 25, 26, 27, 60, 61, + 62, 63, 55, 56, 57, 58, 74, 75, 76, 77, 59, 64, 65, 28, 29, + 30, 44, 45, 46, 47, 50, 51, 52, 53, 54, 48, 49, 31, 32, 33, + 34, 35, 36, 66, 67, 68, 69, 70, 71, 72, 73, 37}}); } TEST_F(PathTracingTest, Handle_Intra_01) { @@ -797,7 +829,7 @@ std::vector> getPaths(const GraphTy &G) { TEST(PathsDAGTest, InLLVMSSA) { psr::LLVMProjectIRDB IRDB(PathTracingTest::PathToLlFiles + "inter_01_cpp.ll"); - psr::LLVMTypeHierarchy TH(IRDB); + psr::DIBasedTypeHierarchy TH(IRDB); psr::LLVMAliasSet PT(&IRDB); psr::LLVMBasedICFG ICFG(&IRDB, psr::CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, psr::Soundness::Soundy, diff --git a/unittests/PhasarLLVM/Pointer/LLVMAliasSetSerializationTest.cpp b/unittests/PhasarLLVM/Pointer/LLVMAliasSetSerializationTest.cpp index 1da745937..73bb6d152 100644 --- a/unittests/PhasarLLVM/Pointer/LLVMAliasSetSerializationTest.cpp +++ b/unittests/PhasarLLVM/Pointer/LLVMAliasSetSerializationTest.cpp @@ -3,7 +3,7 @@ #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Passes/ValueAnnotationPass.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/Utils/Logger.h" #include "llvm/ADT/StringRef.h" @@ -80,7 +80,7 @@ static void analyze(llvm::StringRef File, const GroundTruthTy &Gt, // llvm::outs() << *IRDB.getWPAModule() << '\n'; LLVMAliasSet PTS(&IRDB, false); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMBasedICFG ICF(&IRDB, CallGraphAnalysisType::OTF, {EntryPoint.str()}, &TH, &PTS); @@ -103,11 +103,11 @@ TEST(LLVMAliasSetSerializationTest, Ser_Inter01) { TEST(LLVMAliasSetSerializationTest, Ser_Global01) { analyze("pointers/global_01_cpp.ll", - {{{"0", "15", "17", "2", "3", "9", "_Z3fooPi.0"}, + {{{"0", "14", "16", "2", "8", "_Z3fooPi.0"}, {"1"}, + {"11"}, {"12"}, - {"13"}, - {"7"}}, + {"6"}}, {"_GLOBAL__sub_I_global_01.cpp", "_Z3fooPi", "__cxx_global_var_init", "main"}}); } diff --git a/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp b/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp index b6144d68b..74a242dec 100644 --- a/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp +++ b/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp @@ -5,7 +5,7 @@ #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Passes/ValueAnnotationPass.h" #include "phasar/PhasarLLVM/Pointer/LLVMPointsToUtils.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "TestConfig.h" #include "gtest/gtest.h" @@ -32,7 +32,7 @@ TEST(LLVMAliasSet, Inter_01) { ValueAnnotationPass::resetValueID(); LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "pointers/call_01_cpp.ll"); LLVMAliasSet PTS(&IRDB, false); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMBasedICFG ICF(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PTS); const auto *Main = IRDB.getFunctionDefinition("main"); for (const auto &BB : *Main) { @@ -49,7 +49,7 @@ TEST(LLVMAliasSet, Global_01) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "pointers/global_01_cpp.ll"); LLVMAliasSet PTS(&IRDB, false); - LLVMTypeHierarchy TH(IRDB); + DIBasedTypeHierarchy TH(IRDB); LLVMBasedICFG ICF(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PTS); const auto *Main = IRDB.getFunctionDefinition("main"); for (const auto &G : Main->getParent()->globals()) { diff --git a/unittests/PhasarLLVM/TaintConfig/TaintConfigTest.cpp b/unittests/PhasarLLVM/TaintConfig/TaintConfigTest.cpp index bc722d66e..c7af226d5 100644 --- a/unittests/PhasarLLVM/TaintConfig/TaintConfigTest.cpp +++ b/unittests/PhasarLLVM/TaintConfig/TaintConfigTest.cpp @@ -79,7 +79,7 @@ TEST_F(TaintConfigTest, Basic_02) { psr::LLVMTaintConfig Config(IR); llvm::outs() << Config << '\n'; const llvm::Value *I1 = IR.getInstruction(9); - const llvm::Value *I2 = IR.getInstruction(23); + const llvm::Value *I2 = IR.getInstruction(21); ASSERT_TRUE(Config.isSource(I1)); ASSERT_TRUE(Config.isSource(I2)); } @@ -143,10 +143,10 @@ TEST_F(TaintConfigTest, FunMember_02) { psr::LLVMTaintConfig TConfig(IR); // IR.emitPreprocessedIR(llvm::outs(), false); llvm::outs() << TConfig << '\n'; - const llvm::Value *I1 = IR.getInstruction(22); - const llvm::Value *I2 = IR.getInstruction(61); - const llvm::Value *I3 = IR.getInstruction(73); - const llvm::Value *I4 = IR.getInstruction(84); + const llvm::Value *I1 = IR.getInstruction(20); + const llvm::Value *I2 = IR.getInstruction(57); + const llvm::Value *I3 = IR.getInstruction(67); + const llvm::Value *I4 = IR.getInstruction(76); ASSERT_TRUE(TConfig.isSource(I1)); ASSERT_TRUE(TConfig.isSource(I2)); ASSERT_TRUE(TConfig.isSource(I3)); @@ -365,10 +365,12 @@ TEST_F(TaintConfigTest, FunMember_02_Json) { psr::LLVMProjectIRDB IR({PathToJsonTaintConfigTestCode + File}); // IR.emitPreprocessedIR(llvm::outs(), false); psr::LLVMTaintConfig TConfig(IR, JsonConfig); - const llvm::Value *I1 = IR.getInstruction(18); - const llvm::Value *I2 = IR.getInstruction(54); - const llvm::Value *I3 = IR.getInstruction(63); - const llvm::Value *I4 = IR.getInstruction(71); + llvm::outs() << TConfig << '\n'; + + const llvm::Value *I1 = IR.getInstruction(16); + const llvm::Value *I2 = IR.getInstruction(52); + const llvm::Value *I3 = IR.getInstruction(61); + const llvm::Value *I4 = IR.getInstruction(69); ASSERT_TRUE(TConfig.isSource(I1)); ASSERT_TRUE(TConfig.isSource(I2)); ASSERT_TRUE(TConfig.isSource(I3)); diff --git a/unittests/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchyTest.cpp b/unittests/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchyTest.cpp index 0fa9a40bd..0d302c912 100644 --- a/unittests/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchyTest.cpp +++ b/unittests/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchyTest.cpp @@ -27,8 +27,9 @@ TEST(LTHTest, BasicTHReconstruction_1) { LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles + "type_hierarchies/type_hierarchy_1_cpp.ll"); LLVMTypeHierarchy LTH(IRDB); - EXPECT_EQ(LTH.hasType(LTH.getType("struct.Base")), true); - EXPECT_EQ(LTH.hasType(LTH.getType("struct.Child")), true); + + ASSERT_EQ(LTH.hasType(LTH.getType("struct.Base")), true); + ASSERT_EQ(LTH.hasType(LTH.getType("struct.Child")), true); EXPECT_EQ(LTH.getAllTypes().size(), 2U); EXPECT_EQ( LTH.isSubType(LTH.getType("struct.Base"), LTH.getType("struct.Child")), @@ -163,12 +164,10 @@ TEST(LTHTest, BasicTHReconstruction_7) { LLVMTypeHierarchy LTH(IRDB); EXPECT_EQ(LTH.hasType(LTH.getType("struct.Base")), true); EXPECT_EQ(LTH.hasType(LTH.getType("struct.Child")), true); - // has three types because of padding (introduction of intermediate type) - EXPECT_EQ(LTH.getAllTypes().size(), 3U); + EXPECT_EQ(LTH.getAllTypes().size(), 2U); EXPECT_EQ( LTH.isSubType(LTH.getType("struct.Base"), LTH.getType("struct.Child")), true); - EXPECT_EQ(LTH.getSubTypes(LTH.getType("struct.Base")).size(), 2U); EXPECT_EQ(LTH.getSubTypes(LTH.getType("struct.Child")).size(), 1U); auto BaseReachable = LTH.getSubTypes(LTH.getType("struct.Base")); @@ -267,8 +266,7 @@ TEST(LTHTest, TransitivelyReachableTypes) { TH3.getType("struct.NonvirtualStruct"))); ASSERT_TRUE(ReachableTypesNonvirtualstruct3.size() == 1U); - ASSERT_TRUE(ReachableTypesBase4.count(TH4.getType("struct.Base"))); - ASSERT_FALSE(ReachableTypesBase4.count(TH4.getType("struct.Base.base"))); + ASSERT_TRUE(ReachableTypesBase4.count(TH4.getType("struct.Base.base"))); ASSERT_TRUE(ReachableTypesBase4.count(TH4.getType("struct.Child"))); ASSERT_TRUE(ReachableTypesBase4.size() == 2U); ASSERT_TRUE(ReachableTypesChild4.count(TH4.getType("struct.Child"))); diff --git a/unittests/Utils/AnalysisPrinterTest.cpp b/unittests/Utils/AnalysisPrinterTest.cpp index 34a110d53..546c9d304 100644 --- a/unittests/Utils/AnalysisPrinterTest.cpp +++ b/unittests/Utils/AnalysisPrinterTest.cpp @@ -120,7 +120,7 @@ TEST_F(AnalysisPrinterTest, HandleBasicTest_01) { TEST_F(AnalysisPrinterTest, XTaint01) { llvm::DenseMap> GroundTruth; - GroundTruth[15] = {"8"}; + GroundTruth[13] = {"7"}; GroundTruthCollector GroundTruthPrinter = {GroundTruth}; doAnalysisTest("xtaint01_cpp.ll", GroundTruthPrinter, std::monostate{}); } diff --git a/unittests/Utils/LLVMIRToSrcTest.cpp b/unittests/Utils/LLVMIRToSrcTest.cpp index beb7620ed..01f1f4dbd 100644 --- a/unittests/Utils/LLVMIRToSrcTest.cpp +++ b/unittests/Utils/LLVMIRToSrcTest.cpp @@ -5,7 +5,7 @@ #include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" #include "phasar/PhasarLLVM/Passes/ValueAnnotationPass.h" #include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h" -#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" +#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h" #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" @@ -27,7 +27,7 @@ class LLVMIRToSrcTest : public ::testing::Test { static constexpr auto PathToLlFiles = PHASAR_BUILD_SUBFOLDER("llvmIRtoSrc/"); unique_ptr IRDB; - unique_ptr TH; + unique_ptr TH; unique_ptr PT; unique_ptr ICFG; @@ -36,7 +36,7 @@ class LLVMIRToSrcTest : public ::testing::Test { void initialize(const llvm::Twine &IRFile) { IRDB = make_unique(IRFile); - TH = make_unique(*IRDB); + TH = make_unique(*IRDB); PT = make_unique(IRDB.get()); auto EntryPoints = {"main"s}; ICFG = make_unique(IRDB.get(), CallGraphAnalysisType::OTF, diff --git a/unittests/Utils/LLVMShorthandsTest.cpp b/unittests/Utils/LLVMShorthandsTest.cpp index 2c19ff675..e6678d43a 100644 --- a/unittests/Utils/LLVMShorthandsTest.cpp +++ b/unittests/Utils/LLVMShorthandsTest.cpp @@ -52,7 +52,7 @@ TEST(SlotTrackerTest, HandleTwoReferences) { ASSERT_NE(F, nullptr); const auto *Inst = getNthInstruction(F, 6); - llvm::StringRef InstStr = "%0 = load i32, i32* @i, align 4 | ID: 6"; + llvm::StringRef InstStr = "%0 = load i32, ptr @i, align 4 | ID: 6"; { LLVMProjectIRDB IRDB2(IRDB.getModule());