Skip to content

Commit bc56e8b

Browse files
committed
adjust implementation
1 parent 9b6ba5c commit bc56e8b

4 files changed

Lines changed: 134 additions & 105 deletions

File tree

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CheckOptions:
5151
- key: readability-identifier-naming.VariableCase
5252
value: CamelCase
5353
- key: readability-identifier-naming.VariableIgnoredRegexp
54-
value: (c|d|d1|d2|d3|d4|d5|d5_restoredCtx|eP|f|f3|f4|f5|fCalleeSummary|g|n|dPrime|fPrime)
54+
value: (c|d|d1|d2|d3|d4|d5|d5_restoredCtx|eP|f|f3|f4|f5|fCalleeSummary|g|n|nPrime|dPrime|fPrime)
5555
- key: readability-identifier-naming.ParameterIgnoredRegexp
5656
value: (d|d1|d2|d3|d4|d5|eP|f|n)
5757
- key: readability-identifier-naming.FunctionIgnoredRegexp

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

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Philipp Schubert and others
88
*****************************************************************************/
99

10-
#ifndef PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEINSTINTERACTIONALYSIS_H_
11-
#define PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEINSTINTERACTIONALYSIS_H_
10+
#ifndef PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEINSTINTERACTIONALYSIS_H
11+
#define PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEINSTINTERACTIONALYSIS_H
1212

1313
#include <functional>
1414
#include <initializer_list>
@@ -293,9 +293,6 @@ class IDEInstInteractionAnalysisT
293293
}
294294
container_type Facts;
295295
Facts.insert(Src);
296-
if (IDEInstInteractionAnalysisT::isZeroValueImpl(Src)) {
297-
return Facts;
298-
}
299296
// y/Y now obtains its new value(s) from x/X
300297
// If a value is stored that holds we must generate all potential
301298
// memory locations the store might write to.
@@ -304,6 +301,12 @@ class IDEInstInteractionAnalysisT
304301
Facts.insert(Store->getPointerOperand());
305302
Facts.insert(PointerPTS->begin(), PointerPTS->end());
306303
}
304+
// ... or from zero, if a constant literal is stored to y
305+
if (llvm::isa<llvm::ConstantData>(Store->getValueOperand()) &&
306+
IDEInstInteractionAnalysisT::isZeroValueImpl(Src)) {
307+
Facts.insert(Store->getPointerOperand());
308+
Facts.insert(PointerPTS->begin(), PointerPTS->end());
309+
}
307310
return Facts;
308311
}
309312
};
@@ -384,11 +387,22 @@ class IDEInstInteractionAnalysisT
384387
~IIAAFlowFunction() override = default;
385388

386389
container_type computeTargets(d_t Src) override {
390+
// Override old value, i.e., kill value that is written to and
391+
// generate from value that is stored.
392+
if (Store->getPointerOperand() == Src) {
393+
return {};
394+
}
387395
container_type Facts;
388396
Facts.insert(Src);
397+
// y now obtains its new value from x
389398
if (Store->getValueOperand() == Src) {
390399
Facts.insert(Store->getPointerOperand());
391400
}
401+
// ... or from zero, if a constant literal is stored to y
402+
if (llvm::isa<llvm::ConstantData>(Store->getValueOperand()) &&
403+
IDEInstInteractionAnalysisT::isZeroValueImpl(Src)) {
404+
Facts.insert(Store->getPointerOperand());
405+
}
392406
LOG_IF_ENABLE([&]() {
393407
for (const auto s : Facts) {
394408
BOOST_LOG_SEV(lg::get(), DFADEBUG)
@@ -552,7 +566,7 @@ class IDEInstInteractionAnalysisT
552566
}
553567
}
554568
}
555-
// Just use the auto mapping for values, pointer parameters and global
569+
// Just use the auto mapping for values; pointer parameters and global
556570
// variables are killed and handled by getCallFlowfunction() and
557571
// getRetFlowFunction().
558572
// However, if only declarations are available as callee targets we would
@@ -573,9 +587,18 @@ class IDEInstInteractionAnalysisT
573587
globals here (as they are propagated via call- and
574588
ret-functions. */
575589
,
576-
[](const llvm::CallBase * /* CS */, const llvm::Value * /* V */) {
577-
return false; // treat as not involved in the call since this also
578-
// caputes usages of the parameter
590+
[](const llvm::CallBase * /* CS */, const llvm::Value *V) {
591+
// Treat global variables as involved, since we wish to have them
592+
// handled by getCallFlowFunction() and getRetFlowFunction() to model
593+
// potential effects of the callee.
594+
// Constants covers global variables as well as ConstantExpr and
595+
// ConstantAggregate
596+
if (llvm::isa<llvm::Constant>(V)) {
597+
return true;
598+
}
599+
// Treat all other values as not involved in the call since this also
600+
// captures usages of the parameter.
601+
return false;
579602
});
580603
}
581604

@@ -631,7 +654,7 @@ class IDEInstInteractionAnalysisT
631654
d_t SuccNode) override {
632655
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
633656
<< "Process edge: " << llvmIRToShortString(CurrNode) << " --"
634-
<< llvmIRToShortString(Curr) << "--> "
657+
<< llvmIRToString(Curr) << "--> "
635658
<< llvmIRToShortString(SuccNode));
636659
//
637660
// Zero --> Zero edges
@@ -746,7 +769,7 @@ class IDEInstInteractionAnalysisT
746769
BOOST_LOG_SEV(lg::get(), DFADEBUG)
747770
<< "at '" << llvmIRToString(Curr) << "'\n";
748771
}());
749-
return IIAAKillOrReplaceEF::createEdgeFunction(UserEdgeFacts);
772+
return IIAAAddLabelsEF::createEdgeFunction(UserEdgeFacts);
750773
}
751774
// Kill all labels that are propagated along the edge of the value that
752775
// is overridden.
@@ -1080,13 +1103,13 @@ class IDEInstInteractionAnalysisT
10801103
l_t Replacement;
10811104

10821105
explicit IIAAKillOrReplaceEF() : Replacement(BitVectorSet<e_t>()) {
1083-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1084-
<< "IIAAKillOrReplaceEF");
1106+
// LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1107+
// << "IIAAKillOrReplaceEF");
10851108
}
10861109

10871110
explicit IIAAKillOrReplaceEF(l_t Replacement) : Replacement(Replacement) {
1088-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1089-
<< "IIAAKillOrReplaceEF");
1111+
// LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1112+
// << "IIAAKillOrReplaceEF");
10901113
}
10911114

10921115
~IIAAKillOrReplaceEF() override = default;
@@ -1095,9 +1118,9 @@ class IDEInstInteractionAnalysisT
10951118

10961119
std::shared_ptr<EdgeFunction<l_t>>
10971120
composeWith(std::shared_ptr<EdgeFunction<l_t>> SecondFunction) override {
1098-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1099-
<< "IIAAKillOrReplaceEF::composeWith(): " << this->str()
1100-
<< " * " << SecondFunction->str());
1121+
// LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1122+
// << "IIAAKillOrReplaceEF::composeWith(): " << this->str()
1123+
// << " * " << SecondFunction->str());
11011124
if (auto *AT = dynamic_cast<AllTop<l_t> *>(SecondFunction.get())) {
11021125
return this->shared_from_this();
11031126
}
@@ -1193,7 +1216,7 @@ class IDEInstInteractionAnalysisT
11931216
const l_t Data;
11941217

11951218
explicit IIAAAddLabelsEF(l_t Data) : Data(Data) {
1196-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG) << "IIAAAddLabelsEF");
1219+
// LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG) << "IIAAAddLabelsEF");
11971220
}
11981221

11991222
~IIAAAddLabelsEF() override = default;
@@ -1204,9 +1227,10 @@ class IDEInstInteractionAnalysisT
12041227

12051228
std::shared_ptr<EdgeFunction<l_t>>
12061229
composeWith(std::shared_ptr<EdgeFunction<l_t>> SecondFunction) override {
1207-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1208-
<< "IIAAAddLabelEF::composeWith(): " << this->str() << " * "
1209-
<< SecondFunction->str());
1230+
// LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DFADEBUG)
1231+
// << "IIAAAddLabelEF::composeWith(): " << this->str() << "
1232+
// * "
1233+
// << SecondFunction->str());
12101234
if (auto *AT = dynamic_cast<AllTop<l_t> *>(SecondFunction.get())) {
12111235
return this->shared_from_this();
12121236
}

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -682,30 +682,30 @@ class IDESolver
682682
n_t n = Edge.getTarget();
683683
d_t d2 = Edge.factAtTarget();
684684
EdgeFunctionPtrType f = jumpFunction(Edge);
685-
for (const auto Fn : ICF->getSuccsOf(n)) {
685+
for (const auto nPrime : ICF->getSuccsOf(n)) {
686686
FlowFunctionPtrType FlowFunc =
687-
CachedFlowEdgeFunctions.getNormalFlowFunction(n, Fn);
687+
CachedFlowEdgeFunctions.getNormalFlowFunction(n, nPrime);
688688
INC_COUNTER("FF Queries", 1, PAMM_SEVERITY_LEVEL::Full);
689689
const container_type Res = computeNormalFlowFunction(FlowFunc, d1, d2);
690690
ADD_TO_HISTOGRAM("Data-flow facts", res.size(), 1,
691691
PAMM_SEVERITY_LEVEL::Full);
692-
saveEdges(n, Fn, d2, Res, false);
692+
saveEdges(n, nPrime, d2, Res, false);
693693
for (d_t d3 : Res) {
694694
EdgeFunctionPtrType g =
695-
CachedFlowEdgeFunctions.getNormalEdgeFunction(n, d2, Fn, d3);
695+
CachedFlowEdgeFunctions.getNormalEdgeFunction(n, d2, nPrime, d3);
696696
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
697697
<< "Queried Normal Edge Function: " << g->str());
698698
EdgeFunctionPtrType fPrime = f->composeWith(g);
699699
if (SolverConfig.emitESG()) {
700-
IntermediateEdgeFunctions[std::make_tuple(n, d2, Fn, d3)].push_back(
701-
g);
700+
IntermediateEdgeFunctions[std::make_tuple(n, d2, nPrime, d3)]
701+
.push_back(g);
702702
}
703703
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
704704
<< "Compose: " << g->str() << " * " << f->str()
705705
<< " = " << fPrime->str();
706706
BOOST_LOG_SEV(lg::get(), DEBUG) << ' ');
707707
INC_COUNTER("EF Queries", 1, PAMM_SEVERITY_LEVEL::Full);
708-
propagate(d1, Fn, d3, fPrime, nullptr, false);
708+
propagate(d1, nPrime, d3, fPrime, nullptr, false);
709709
}
710710
}
711711
}

0 commit comments

Comments
 (0)