Skip to content

Commit c9dedb3

Browse files
committed
Merge branch 'development' into f-RedesignICFG
2 parents ca1901d + 11aab80 commit c9dedb3

4 files changed

Lines changed: 50 additions & 36 deletions

File tree

include/phasar/Config/Configuration.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
#ifndef PHASAR_CONFIG_CONFIGURATION_H_
1818
#define PHASAR_CONFIG_CONFIGURATION_H_
1919

20-
#include <filesystem>
21-
#include <string>
22-
23-
#include "boost/program_options.hpp"
20+
#include "phasar/Config/Version.h"
2421

2522
#include "llvm/ADT/iterator_range.h"
2623

27-
#include "phasar/Config/Version.h"
24+
#include "boost/program_options.hpp"
25+
26+
#include <filesystem>
27+
#include <string>
2828

2929
#define XSTR(S) STR(S)
3030
#define STR(S) #S

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEInstInteractionAnalysis.h

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -833,23 +833,43 @@ class IDEInstInteractionAnalysisT
833833
struct MapFactsAlongsideCallSite : public FlowFunction<IDEIIAFlowFact> {
834834
bool OnlyDecls;
835835
const llvm::CallBase *CallSite;
836+
d_t ZeroValue;
837+
std::set<f_t> Callees;
836838

837-
MapFactsAlongsideCallSite(bool OnlyDecls, const llvm::CallBase *CallSite)
838-
: OnlyDecls(OnlyDecls), CallSite(CallSite) {}
839+
MapFactsAlongsideCallSite(bool OnlyDecls, const llvm::CallBase *CallSite,
840+
d_t ZeroValue, std::set<f_t> Callees)
841+
: OnlyDecls(OnlyDecls), CallSite(CallSite), ZeroValue(ZeroValue),
842+
Callees(Callees) {}
839843

840844
std::set<IDEIIAFlowFact> computeTargets(IDEIIAFlowFact Source) override {
841-
// Pass ZeroValue as is
842-
if (LLVMZeroValue::getInstance()->isLLVMZeroValue(Source.getBase())) {
843-
return {Source};
844-
}
845-
// Pass variables as identity, if no function definition is available
846-
// as they would be otherwise killed.
845+
// There are a few things to consider, in case only declarations of
846+
// callee targets are available.
847847
if (OnlyDecls) {
848-
return {Source};
848+
auto AllVoidRetTys = [](const std::set<f_t> &Callees) {
849+
// Check if one of the callee targets returns a value.
850+
bool AllVoidRetTys = true;
851+
for (const auto *Callee : Callees) {
852+
if (!Callee->getReturnType()->isVoidTy()) {
853+
AllVoidRetTys = false;
854+
}
855+
}
856+
return AllVoidRetTys;
857+
};
858+
if (!AllVoidRetTys(Callees)) {
859+
// If one or more of the declaration-only targets return a value, it
860+
// must be generated from zero!
861+
if (Source == ZeroValue) {
862+
return {Source, CallSite};
863+
}
864+
} else {
865+
// If all declaration-only callee targets return void, just pass
866+
// everything as identity.
867+
return {Source};
868+
}
849869
}
850-
// Do not global variables (if definitions of the callee function(s) are
851-
// available), since the effect of the callee on these values will be
852-
// modelled using combined getCallFlowFunction and
870+
// Do not pass global variables if definitions of the callee
871+
// function(s) are available, since the effect of the callee on these
872+
// values will be modelled using combined getCallFlowFunction and
853873
// getReturnFlowFunction.
854874
if (llvm::isa<llvm::Constant>(Source.getBase())) {
855875
return {};
@@ -861,7 +881,8 @@ class IDEInstInteractionAnalysisT
861881
}
862882
};
863883
return std::make_shared<MapFactsAlongsideCallSite>(
864-
OnlyDecls, llvm::dyn_cast<llvm::CallBase>(CallSite));
884+
OnlyDecls, llvm::dyn_cast<llvm::CallBase>(CallSite),
885+
this->getZeroValue(), Callees);
865886
}
866887

867888
inline FlowFunctionPtrType
@@ -1716,7 +1737,7 @@ class IDEInstInteractionAnalysisT
17161737
}
17171738

17181739
private:
1719-
/// Filters out all variables that had a non empty set during edge functions
1740+
/// Filters out all variables that had a non-empty set during edge functions
17201741
/// computations.
17211742
inline std::unordered_set<d_t> removeVariablesWithoutEmptySetValue(
17221743
const SolverResults<n_t, d_t, l_t> &Solution,
@@ -1730,7 +1751,7 @@ class IDEInstInteractionAnalysisT
17301751
// at some point. Therefore, we only care for the variables and their
17311752
// associated values and ignore at which point a variable may holds as a
17321753
// data-flow fact.
1733-
const auto *Variable = Result.getColumnKey();
1754+
const auto Variable = Result.getColumnKey();
17341755
const auto &Value = Result.getValue();
17351756
// skip result entry if variable is not in the set of all variables
17361757
if (Variables.find(Variable) == Variables.end()) {

unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEInstInteractionAnalysisTest.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,8 @@ class IDEInstInteractionAnalysisTest : public ::testing::Test {
128128
llvm::raw_string_ostream RSO(FactStr);
129129
RSO << *Fact.getBase();
130130
llvm::StringRef FactRef(FactStr);
131-
// llvm::outs() << "Iterating result map entry: " << Fact << ", " <<
132-
// Value
133-
// << " with FactRef: " << FactRef
134-
// << " and VarName: " << VarName << '\n';
135131
if (FactRef.ltrim().startswith("%" + VarName + " ") ||
136132
FactRef.ltrim().startswith("@" + VarName + " ")) {
137-
// llvm::outs() << "Found fact: " << FactRef.ltrim() << '\n';
138-
// llvm::outs() << "Compare Value: " << Value
139-
// << " and LatticeVal: " << LatticeVal << '\n';
140133
PHASAR_LOG_LEVEL(DFADEBUG, "Checking variable: " << FactStr);
141134
EXPECT_EQ(LatticeVal, Value);
142135
FactFound = true;
@@ -146,8 +139,6 @@ class IDEInstInteractionAnalysisTest : public ::testing::Test {
146139
PHASAR_LOG_LEVEL(DFADEBUG, "Variable '" << VarName << "' missing at '"
147140
<< llvmIRToString(IRLine)
148141
<< "'.");
149-
// llvm::outs() << "Variable '" << VarName << "' missing at '"
150-
// << llvmIRToString(IRLine) << "'.";
151142
}
152143
EXPECT_TRUE(FactFound);
153144
}
@@ -505,16 +496,16 @@ PHASAR_SKIP_TEST(TEST_F(IDEInstInteractionAnalysisTest, HandleBasicTest_04) {
505496
"main", 23, "argc.addr", {"14", "21"}));
506497
GroundTruth.emplace(
507498
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
508-
"main", 24, "argv.addr", {"9", "15"}));
499+
"main", 23, "argv.addr", {"15"}));
509500
GroundTruth.emplace(
510501
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
511-
"main", 24, "i", {"10", "16", "17"}));
502+
"main", 23, "i", {"16", "17"}));
512503
GroundTruth.emplace(
513504
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
514-
"main", 24, "j", {"10", "11", "16", "19", "24"}));
505+
"main", 23, "j", {"16", "17", "19", "18", "24"}));
515506
GroundTruth.emplace(
516507
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
517-
"main", 24, "k", {"10", "11", "12", "16", "19", "20", "25", "27"}));
508+
"main", 23, "k", {"16", "17", "18", "19", "20", "24", "25", "27"}));
518509
doAnalysisAndCompareResults("basic_04_cpp.ll", {"main"}, GroundTruth, false);
519510
})
520511

@@ -873,7 +864,7 @@ PHASAR_SKIP_TEST(TEST_F(IDEInstInteractionAnalysisTest, HandleRVOTest_01) {
873864
std::set<IIACompactResult_t> GroundTruth;
874865
GroundTruth.emplace(
875866
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
876-
"main", 16, "retval", {"23", "35", "37"}));
867+
"main", 16, "retval", {"75", "76", "78"}));
877868
GroundTruth.emplace(
878869
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
879870
"main", 16, "str", {"70", "65", "72", "74", "77"}));

unittests/TestUtils/TestConfig.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#ifndef UNITTEST_TESTUTILS_TESTCONFIG_H_
22
#define UNITTEST_TESTUTILS_TESTCONFIG_H_
33

4-
#include <string>
5-
64
#include "phasar/Config/Configuration.h"
75

6+
#include "gtest/gtest.h"
7+
8+
#include <string>
9+
810
namespace psr::unittest {
911

1012
inline const std::string PathToLLTestFiles(PhasarConfig::PhasarDirectory() +

0 commit comments

Comments
 (0)