Skip to content

Commit

Permalink
implemented review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mxHuber committed Aug 4, 2024
1 parent 8a4d812 commit fd11ada
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 106 deletions.
1 change: 0 additions & 1 deletion include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
#include "phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"
#include "phasar/PhasarLLVM/Utils/LLVMBasedContainerConfig.h"
#include "phasar/Utils/Soundness.h"

Expand Down
2 changes: 0 additions & 2 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#include "phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h"

#include "llvm/IR/DebugInfoMetadata.h"

#include <unordered_map>

namespace llvm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define PHASAR_PHASARLLVM_CONTROLFLOW_RESOLVER_CHARESOLVER_H_

#include "phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h"
#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"
#include "phasar/Utils/MaybeUniquePtr.h"

namespace llvm {
Expand Down
4 changes: 2 additions & 2 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

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

#include "llvm/IR/DebugInfoMetadata.h"

#include <vector>

namespace llvm {
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,
Expand Down
5 changes: 1 addition & 4 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#define PHASAR_PHASARLLVM_CONTROLFLOW_RESOLVER_RESOLVER_H_

#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"

#include "llvm/ADT/DenseSet.h"
#include "llvm/IR/DerivedTypes.h"

#include <memory>
#include <optional>
Expand All @@ -45,9 +45,6 @@ getVFTIndex(const llvm::CallBase *CallSite);
[[nodiscard]] const llvm::DIType *
getReceiverType(const llvm::CallBase *CallSite);

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

[[nodiscard]] std::string getReceiverTypeName(const llvm::CallBase *CallSite);

[[nodiscard]] bool isConsistentCall(const llvm::CallBase *CallSite,
Expand Down
3 changes: 1 addition & 2 deletions include/phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

#include "phasar/Domain/AnalysisDomain.h"

#include "llvm/IR/DebugInfoMetadata.h"

namespace llvm {
class Value;
class Instruction;
class StructType;
class Function;
class DIType;
} // namespace llvm

namespace psr {
Expand Down
2 changes: 2 additions & 0 deletions include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ConstantStruct;
} // namespace llvm

namespace psr {
class DIBasedTypeHierarchy;

/**
* @brief Represents a virtual method table.
Expand All @@ -30,6 +31,7 @@ namespace psr {
* virtual method table matters.
*/
class LLVMVFTable : public VFTable<const llvm::Function *> {

private:
friend class DIBasedTypeHierarchy;
std::vector<const llvm::Function *> VFT;
Expand Down
20 changes: 8 additions & 12 deletions lib/PhasarLLVM/ControlFlow/LLVMVFTableProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ static std::vector<const llvm::Function *> getVirtualFunctions(
const llvm::DIType *Type) {
auto ClearName = getTypeName(Type);

if (llvm::StringRef(ClearName).startswith("typeinfo name for ")) {
ClearName = ClearName.substr(18, ClearName.size() - 1);
static constexpr llvm::StringLiteral TIPrefix = "typeinfo name for ";
if (llvm::StringRef(ClearName).startswith(TIPrefix)) {
ClearName = ClearName.substr(TIPrefix.size());
}

auto It = ClearNameTVMap.find(ClearName);
Expand Down Expand Up @@ -64,16 +65,11 @@ LLVMVFTableProvider::LLVMVFTableProvider(const llvm::Module &Mod) {
llvm::DebugInfoFinder DIF;
DIF.processModule(Mod);
for (const auto *Ty : DIF.types()) {
if (const auto *DerivedTy = llvm::dyn_cast<llvm::DIDerivedType>(Ty)) {
if (const auto *BaseTy = DerivedTy->getBaseType()) {
if (const auto *CompTy =
llvm::dyn_cast<llvm::DICompositeType>(BaseTy)) {
if (CompTy->getTag() == llvm::dwarf::DW_TAG_class_type ||
CompTy->getTag() == llvm::dwarf::DW_TAG_structure_type) {
TypeVFTMap.try_emplace(CompTy,
getVirtualFunctions(ClearNameTVMap, CompTy));
}
}
if (const auto *CompTy = llvm::dyn_cast<llvm::DICompositeType>(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));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/PhasarLLVM/ControlFlow/Resolver/CHAResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 2 additions & 8 deletions lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.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 "phasar/Utils/Utilities.h"

#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
Expand Down Expand Up @@ -99,16 +99,10 @@ void RTAResolver::resolveAllocatedCompositeTypes() {

llvm::DebugInfoFinder DIF;
DIF.processModule(*IRDB->getModule());
llvm::DenseSet<const llvm::DICompositeType *> AllocatedCompositeTypes;

for (const auto *Ty : DIF.types()) {
if (const auto *CompTy = llvm::dyn_cast<llvm::DICompositeType>(Ty)) {
AllocatedCompositeTypes.insert(CompTy);
AllocatedCompositeTypes.push_back(CompTy);
}
}

this->AllocatedCompositeTypes.reserve(AllocatedCompositeTypes.size());
this->AllocatedCompositeTypes.insert(this->AllocatedCompositeTypes.end(),
AllocatedCompositeTypes.begin(),
AllocatedCompositeTypes.end());
}
51 changes: 0 additions & 51 deletions lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,57 +83,6 @@ const llvm::DIType *psr::getReceiverType(const llvm::CallBase *CallSite) {
}
}
}
/*
if (Receiver->getType()->isOpaquePointerTy()) {
if (const auto *Load = llvm::dyn_cast<llvm::LoadInst>(Receiver)) {
if (const auto *DerivedTy = llvm::dyn_cast<llvm::DIDerivedType>(
getDILocalVariable(Load->getPointerOperand())->getType())) {
return DerivedTy->getBaseType();
}
}
}
if (!Receiver->getType()->isOpaquePointerTy()) {
if (const auto *ReceiverTy = llvm::dyn_cast<llvm::StructType>(
Receiver->getType()->getNonOpaquePointerElementType())) {
if (const auto *ValueTy = llvm::dyn_cast<llvm::Type>(ReceiverTy)) {
if (const auto *DerivedTy = llvm::dyn_cast<llvm::DIDerivedType>(
getDILocalVariable(TypeToDIType[ValueTy]))) {
return DerivedTy->getBaseType();
}
}
}
}
*/
return nullptr;
}

const llvm::StructType *
psr::getReceiverStructType(const llvm::CallBase *CallSite) {
if (CallSite->arg_empty() ||
(CallSite->hasStructRetAttr() && CallSite->arg_size() < 2)) {
return nullptr;
}

const auto *Receiver =
CallSite->getArgOperand(unsigned(CallSite->hasStructRetAttr()));

if (!Receiver->getType()->isPointerTy()) {
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<llvm::StructType>(
Receiver->getType()->getNonOpaquePointerElementType())) {
return ReceiverTy;
}
}

return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ auto DIBasedTypeHierarchy::subTypesOf(ClassType Ty) const noexcept
}

bool DIBasedTypeHierarchy::isVTable(llvm::StringRef VarName) {
if (VarName.startswith("_ZTV")) {
if (VarName.startswith(VTablePrefix)) {
return true;
}
// In LLVM 16 demangle() takes a StringRef
Expand Down
2 changes: 2 additions & 0 deletions tools/example-tool/myphasartool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Philipp Schubert and others
*****************************************************************************/

#include "phasar/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.h"

#include "phasar.h"

#include <filesystem>
Expand Down
8 changes: 1 addition & 7 deletions unittests/PhasarLLVM/ControlFlow/LLVMBasedICFGExportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ class LLVMBasedICFGExportTest : public ::testing::Test {
const nlohmann::json &GroundTruth) {
ASSERT_TRUE(ExportedICFG.is_array());

// llvm::outs() << "JSONs: GroundTruth\n";
// llvm::outs() << GroundTruth.dump() << "\n";
// llvm::outs() << "\n\n------------------------------------------\n\n";
// llvm::outs() << "JSONs: ExportedICFG\n";
// llvm::outs() << ExportedICFG.dump() << "\n";

EXPECT_EQ(GroundTruth.size(), ExportedICFG.size());
bool HasError = false;
for (const auto &GTJson : GroundTruth) {
Expand All @@ -178,7 +172,7 @@ class LLVMBasedICFGExportTest : public ::testing::Test {
}

if (HasError) {
// llvm::errs() << "Errorneous json: " << ExportedICFG.dump(4) << '\n';
llvm::errs() << "Errorneous json: " << ExportedICFG.dump(4) << '\n';
}
}

Expand Down
4 changes: 2 additions & 2 deletions unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_DTATest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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"

Expand All @@ -12,7 +13,7 @@
using namespace std;
using namespace psr;
TEST(LLVMBasedICFG_DTATest, VirtualCallSite_5) {
#if 0
GTEST_SKIP();
LLVMProjectIRDB IRDB(unittest::PathToLLTestFiles +
"call_graphs/virtual_call_5_cpp.ll");
DIBasedTypeHierarchy TH(IRDB);
Expand All @@ -38,7 +39,6 @@ TEST(LLVMBasedICFG_DTATest, VirtualCallSite_5) {
ASSERT_TRUE(llvm::is_contained(ICFG.getCallersOf(VFuncA), I));
ASSERT_TRUE(llvm::is_contained(ICFG.getCallersOf(VFuncB), I));
}
#endif
}

TEST(LLVMBasedICFG_DTATest, VirtualCallSite_6) {
Expand Down
1 change: 1 addition & 0 deletions unittests/PhasarLLVM/ControlFlow/LLVMBasedICFG_OTFTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ TEST_F(IDEGeneralizedLCATest, StringTestCpp) {
std::vector<groundTruth_t> 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);
LCASolver->dumpResults();
}

TEST_F(IDEGeneralizedLCATest, FloatDivisionTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ TEST_F(IDEInstInteractionAnalysisTest, StructEquality_01) {

TEST_F(IDEInstInteractionAnalysisTest, StructEquality_02) {
initializeIR("struct_02_cpp.ll");
IRDB->dump();
const auto *Main = IRDB->getFunction("main");
const auto *Inst = getNthInstruction(Main, 2);
auto FlowFact = IDEIIAFlowFact::create(Inst);
Expand Down
8 changes: 0 additions & 8 deletions utils/install-llvm-only.sh

This file was deleted.

0 comments on commit fd11ada

Please sign in to comment.