Skip to content

Commit 11aab80

Browse files
committed
further IDEIIAA fixes
1 parent 7b7c8de commit 11aab80

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
@@ -1715,7 +1736,7 @@ class IDEInstInteractionAnalysisT
17151736
}
17161737

17171738
private:
1718-
/// Filters out all variables that had a non empty set during edge functions
1739+
/// Filters out all variables that had a non-empty set during edge functions
17191740
/// computations.
17201741
inline std::unordered_set<d_t> removeVariablesWithoutEmptySetValue(
17211742
const SolverResults<n_t, d_t, l_t> &Solution,
@@ -1729,7 +1750,7 @@ class IDEInstInteractionAnalysisT
17291750
// at some point. Therefore, we only care for the variables and their
17301751
// associated values and ignore at which point a variable may holds as a
17311752
// data-flow fact.
1732-
const auto *Variable = Result.getColumnKey();
1753+
const auto Variable = Result.getColumnKey();
17331754
const auto &Value = Result.getValue();
17341755
// skip result entry if variable is not in the set of all variables
17351756
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
@@ -126,15 +126,8 @@ class IDEInstInteractionAnalysisTest : public ::testing::Test {
126126
llvm::raw_string_ostream RSO(FactStr);
127127
RSO << *Fact.getBase();
128128
llvm::StringRef FactRef(FactStr);
129-
// llvm::outs() << "Iterating result map entry: " << Fact << ", " <<
130-
// Value
131-
// << " with FactRef: " << FactRef
132-
// << " and VarName: " << VarName << '\n';
133129
if (FactRef.ltrim().startswith("%" + VarName + " ") ||
134130
FactRef.ltrim().startswith("@" + VarName + " ")) {
135-
// llvm::outs() << "Found fact: " << FactRef.ltrim() << '\n';
136-
// llvm::outs() << "Compare Value: " << Value
137-
// << " and LatticeVal: " << LatticeVal << '\n';
138131
PHASAR_LOG_LEVEL(DFADEBUG, "Checking variable: " << FactStr);
139132
EXPECT_EQ(LatticeVal, Value);
140133
FactFound = true;
@@ -144,8 +137,6 @@ class IDEInstInteractionAnalysisTest : public ::testing::Test {
144137
PHASAR_LOG_LEVEL(DFADEBUG, "Variable '" << VarName << "' missing at '"
145138
<< llvmIRToString(IRLine)
146139
<< "'.");
147-
// llvm::outs() << "Variable '" << VarName << "' missing at '"
148-
// << llvmIRToString(IRLine) << "'.";
149140
}
150141
EXPECT_TRUE(FactFound);
151142
}
@@ -503,16 +494,16 @@ PHASAR_SKIP_TEST(TEST_F(IDEInstInteractionAnalysisTest, HandleBasicTest_04) {
503494
"main", 23, "argc.addr", {"14", "21"}));
504495
GroundTruth.emplace(
505496
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
506-
"main", 24, "argv.addr", {"9", "15"}));
497+
"main", 23, "argv.addr", {"15"}));
507498
GroundTruth.emplace(
508499
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
509-
"main", 24, "i", {"10", "16", "17"}));
500+
"main", 23, "i", {"16", "17"}));
510501
GroundTruth.emplace(
511502
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
512-
"main", 24, "j", {"10", "11", "16", "19", "24"}));
503+
"main", 23, "j", {"16", "17", "19", "18", "24"}));
513504
GroundTruth.emplace(
514505
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
515-
"main", 24, "k", {"10", "11", "12", "16", "19", "20", "25", "27"}));
506+
"main", 23, "k", {"16", "17", "18", "19", "20", "24", "25", "27"}));
516507
doAnalysisAndCompareResults("basic_04_cpp.ll", {"main"}, GroundTruth, false);
517508
})
518509

@@ -871,7 +862,7 @@ PHASAR_SKIP_TEST(TEST_F(IDEInstInteractionAnalysisTest, HandleRVOTest_01) {
871862
std::set<IIACompactResult_t> GroundTruth;
872863
GroundTruth.emplace(
873864
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
874-
"main", 16, "retval", {"23", "35", "37"}));
865+
"main", 16, "retval", {"75", "76", "78"}));
875866
GroundTruth.emplace(
876867
std::tuple<std::string, size_t, std::string, BitVectorSet<std::string>>(
877868
"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)