Skip to content

Commit eeb0841

Browse files
committed
adjusted a few minor things
1 parent 4f1d3ac commit eeb0841

13 files changed

Lines changed: 97 additions & 83 deletions

File tree

examples/plugins/MyIFDSProblem.cxx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#include <iostream>
1+
#include <memory>
2+
3+
#include "llvm/Support/raw_ostream.h"
24

35
#include "phasar/DB/ProjectIRDB.h"
46
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
@@ -8,26 +10,27 @@
810

911
#include "MyIFDSProblem.h"
1012

11-
using namespace std;
1213
using namespace psr;
1314

1415
// Factory function that is used to create an instance by the Phasar framework.
15-
unique_ptr<IFDSTabulationProblemPlugin>
16+
std::unique_ptr<IFDSTabulationProblemPlugin>
1617
makeMyIFDSProblem(const ProjectIRDB *IRDB, const LLVMTypeHierarchy *TH,
1718
const LLVMBasedICFG *ICF, LLVMPointsToInfo *PT,
1819
std::set<std::string> EntryPoints) {
19-
return unique_ptr<IFDSTabulationProblemPlugin>(
20+
return std::unique_ptr<IFDSTabulationProblemPlugin>(
2021
new MyIFDSProblem(IRDB, TH, ICF, PT, EntryPoints));
2122
}
2223

2324
// Is executed on plug-in load and has to register this plug-in to Phasar.
2425
__attribute__((constructor)) void init() {
25-
cout << "init - MyIFDSProblem\n";
26+
llvm::outs() << "init - MyIFDSProblem\n";
2627
IFDSTabulationProblemPluginFactory["MyIFDSProblem"] = &makeMyIFDSProblem;
2728
}
2829

2930
// Is executed on unload, can be used to unregister the plug-in.
30-
__attribute__((destructor)) void fini() { cout << "fini - MyIFDSProblem\n"; }
31+
__attribute__((destructor)) void fini() {
32+
llvm::outs() << "fini - MyIFDSProblem\n";
33+
}
3134

3235
MyIFDSProblem::MyIFDSProblem(const ProjectIRDB *IRDB,
3336
const LLVMTypeHierarchy *TH,
@@ -42,7 +45,7 @@ const FlowFact *MyIFDSProblem::createZeroValue() const { return ZeroValue; }
4245
MyIFDSProblem::FlowFunctionPtrType
4346
MyIFDSProblem::getNormalFlowFunction(const llvm::Instruction *curr,
4447
const llvm::Instruction *succ) {
45-
cout << "MyIFDSProblem::getNormalFlowFunction()\n";
48+
llvm::outs() << "MyIFDSProblem::getNormalFlowFunction()\n";
4649
// TODO: Must be implemented to propagate tainted values through the program.
4750
// Tainted values may spread through loads and stores (llvm::LoadInst and
4851
// llvm::StoreInst). Important memberfunctions are getPointerOperand() and
@@ -53,7 +56,7 @@ MyIFDSProblem::getNormalFlowFunction(const llvm::Instruction *curr,
5356
MyIFDSProblem::FlowFunctionPtrType
5457
MyIFDSProblem::getCallFlowFunction(const llvm::Instruction *callSite,
5558
const llvm::Function *destMthd) {
56-
cout << "MyIFDSProblem::getCallFlowFunction()\n";
59+
llvm::outs() << "MyIFDSProblem::getCallFlowFunction()\n";
5760
// TODO: Must be modeled to perform parameter passing:
5861
// actuals at caller-side must be mapped into formals at callee-side.
5962
// LLVM distinguishes between a ordinary function call and a function call
@@ -72,7 +75,7 @@ MyIFDSProblem::getCallFlowFunction(const llvm::Instruction *callSite,
7275
MyIFDSProblem::FlowFunctionPtrType MyIFDSProblem::getRetFlowFunction(
7376
const llvm::Instruction *callSite, const llvm::Function *calleeMthd,
7477
const llvm::Instruction *ExitInst, const llvm::Instruction *retSite) {
75-
cout << "MyIFDSProblem::getRetFlowFunction()\n";
78+
llvm::outs() << "MyIFDSProblem::getRetFlowFunction()\n";
7679
// TODO: Must be modeled to map the return value back into the caller's
7780
// context. When dealing with pointer parameters one must also map the
7881
// formals at callee-side back into the actuals at caller-side. All other
@@ -84,11 +87,10 @@ MyIFDSProblem::FlowFunctionPtrType MyIFDSProblem::getRetFlowFunction(
8487
return Identity<const FlowFact *>::getInstance();
8588
}
8689

87-
MyIFDSProblem::FlowFunctionPtrType
88-
MyIFDSProblem::getCallToRetFlowFunction(const llvm::Instruction *callSite,
89-
const llvm::Instruction *retSite,
90-
set<const llvm::Function *> callees) {
91-
cout << "MyIFDSProblem::getCallToRetFlowFunction()\n";
90+
MyIFDSProblem::FlowFunctionPtrType MyIFDSProblem::getCallToRetFlowFunction(
91+
const llvm::Instruction *callSite, const llvm::Instruction *retSite,
92+
std::set<const llvm::Function *> callees) {
93+
llvm::outs() << "MyIFDSProblem::getCallToRetFlowFunction()\n";
9294
// TODO: Use in combination with getCallFlowFunction to model the effects of
9395
// source and sink functions. It most analyses flow facts can be passed as
9496
// identity.
@@ -101,25 +103,25 @@ MyIFDSProblem::getCallToRetFlowFunction(const llvm::Instruction *callSite,
101103
MyIFDSProblem::FlowFunctionPtrType
102104
MyIFDSProblem::getSummaryFlowFunction(const llvm::Instruction *callSite,
103105
const llvm::Function *destMthd) {
104-
cout << "MyIFDSProblem::getSummaryFlowFunction()\n";
106+
llvm::outs() << "MyIFDSProblem::getSummaryFlowFunction()\n";
105107
return nullptr;
106108
}
107109

108110
// Return(s) set(s) of flow fact(s) that hold(s) initially at a corresponding
109111
// statement. The analysis will start at these instructions and propagate the
110112
// flow facts according to the analysis description.
111-
map<const llvm::Instruction *, set<const FlowFact *>>
113+
std::map<const llvm::Instruction *, std::set<const FlowFact *>>
112114
MyIFDSProblem::initialSeeds() {
113-
cout << "MyIFDSProblem::initialSeeds()\n";
114-
map<const llvm::Instruction *, set<const FlowFact *>> SeedMap;
115+
llvm::outs() << "MyIFDSProblem::initialSeeds()\n";
116+
std::map<const llvm::Instruction *, std::set<const FlowFact *>> SeedMap;
115117
auto EntryPoints = getEntryPoints();
116118
for (const auto &EntryPoint : EntryPoints) {
117119
if (const auto *F = IRDB->getFunctionDefinition(EntryPoint)) {
118-
SeedMap.insert(std::make_pair(&F->front().front(),
119-
set<const FlowFact *>({getZeroValue()})));
120+
SeedMap.insert(std::make_pair(
121+
&F->front().front(), std::set<const FlowFact *>({getZeroValue()})));
120122
} else {
121-
cout << "Could not retrieve function '" << EntryPoint
122-
<< "' --> Function does not exist or is declaration only.\n";
123+
llvm::outs() << "Could not retrieve function '" << EntryPoint
124+
<< "' --> Function does not exist or is declaration only.\n";
123125
}
124126
}
125127
return SeedMap;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,15 @@ class IDEInstInteractionAnalysisT
365365
} else {
366366
Facts.insert(Src);
367367
}
368-
IF_LOG_ENABLED([&]() {
368+
IF_LOG_ENABLED({
369369
for (const auto s : Facts) {
370370
PHASAR_LOG_LEVEL(DFADEBUG,
371371
"Create edge: "
372372
<< llvmIRToShortString(Src) << " --"
373373
<< llvmIRToShortString(Store) << "--> "
374374
<< llvmIRToShortString(s));
375375
}
376-
}());
376+
});
377377
return Facts;
378378
}
379379
};
@@ -403,15 +403,15 @@ class IDEInstInteractionAnalysisT
403403
IDEInstInteractionAnalysisT::isZeroValueImpl(Src)) {
404404
Facts.insert(Store->getPointerOperand());
405405
}
406-
IF_LOG_ENABLED([&]() {
406+
IF_LOG_ENABLED({
407407
for (const auto s : Facts) {
408408
PHASAR_LOG_LEVEL(
409409
DFADEBUG, "Create edge: " << llvmIRToShortString(Src) << " --"
410410
<< llvmIRToShortString(Store)
411411
<< "--> "
412412
<< llvmIRToShortString(s));
413413
}
414-
}());
414+
});
415415
return Facts;
416416
}
417417
};
@@ -459,14 +459,14 @@ class IDEInstInteractionAnalysisT
459459
}
460460
// pass everything that already holds as identity
461461
Facts.insert(Src);
462-
IF_LOG_ENABLED([&]() {
462+
IF_LOG_ENABLED({
463463
for (const auto s : Facts) {
464464
PHASAR_LOG_LEVEL(DFADEBUG, "Create edge: "
465465
<< llvmIRToShortString(Src) << " --"
466466
<< llvmIRToShortString(Inst)
467467
<< "--> " << llvmIRToShortString(s));
468468
}
469-
}());
469+
});
470470
return Facts;
471471
}
472472
};
@@ -771,15 +771,15 @@ class IDEInstInteractionAnalysisT
771771
if ((CurrNode == SuccNode) && CurrNode == Store->getPointerOperand()) {
772772
// y obtains its value(s) from its original allocation and the store
773773
// instruction under analysis.
774-
IF_LOG_ENABLED([&]() {
774+
IF_LOG_ENABLED({
775775
PHASAR_LOG_LEVEL(DFADEBUG,
776776
"Const-Replace at '" << llvmIRToString(Curr));
777777
PHASAR_LOG_LEVEL(DFADEBUG, "Replacement label(s): ");
778778
for (const auto &Item : EdgeFacts) {
779779
PHASAR_LOG_LEVEL(DFADEBUG, Item << ", ");
780780
}
781781
PHASAR_LOG_LEVEL(DFADEBUG, '\n');
782-
}());
782+
});
783783
// obtain label from the original allocation
784784
const llvm::AllocaInst *OrigAlloca = nullptr;
785785
if (const auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(
@@ -811,13 +811,13 @@ class IDEInstInteractionAnalysisT
811811
//
812812
if (CurrNode == Store->getValueOperand() &&
813813
SuccNode == Store->getPointerOperand()) {
814-
IF_LOG_ENABLED([&]() {
814+
IF_LOG_ENABLED({
815815
PHASAR_LOG_LEVEL(DFADEBUG, "Var-Override: ");
816816
for (const auto &EF : EdgeFacts) {
817817
PHASAR_LOG_LEVEL(DFADEBUG, EF << ", ");
818818
}
819819
PHASAR_LOG_LEVEL(DFADEBUG, "at '" << llvmIRToString(Curr) << "'\n");
820-
}());
820+
});
821821
return IIAAAddLabelsEF::createEdgeFunction(UserEdgeFacts);
822822
}
823823
} else {
@@ -919,13 +919,13 @@ class IDEInstInteractionAnalysisT
919919
// o_i
920920
//
921921
if (Op == CurrNode && CurrNode == SuccNode) {
922-
IF_LOG_ENABLED([&]() {
922+
IF_LOG_ENABLED({
923923
PHASAR_LOG_LEVEL(DFADEBUG, "this is 'i'\n");
924924
for (auto &EdgeFact : EdgeFacts) {
925925
PHASAR_LOG_LEVEL(DFADEBUG, EdgeFact << ", ");
926926
}
927927
PHASAR_LOG_LEVEL(DFADEBUG, '\n');
928-
}());
928+
});
929929
return IIAAAddLabelsEF::createEdgeFunction(UserEdgeFacts);
930930
}
931931
//
@@ -940,13 +940,13 @@ class IDEInstInteractionAnalysisT
940940
// i
941941
//
942942
if (Op == CurrNode && Curr == SuccNode) {
943-
IF_LOG_ENABLED([&]() {
943+
IF_LOG_ENABLED({
944944
PHASAR_LOG_LEVEL(DFADEBUG, "this is '0'\n");
945945
for (auto &EdgeFact : EdgeFacts) {
946946
PHASAR_LOG_LEVEL(DFADEBUG, EdgeFact << ", ");
947947
}
948948
PHASAR_LOG_LEVEL(DFADEBUG, '\n');
949-
}());
949+
});
950950
return IIAAAddLabelsEF::createEdgeFunction(UserEdgeFacts);
951951
}
952952
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,14 @@ class IDESolver
754754
}
755755

756756
void setVal(n_t NHashN, d_t NHashD, l_t L) {
757-
IF_LOG_ENABLED([&]() {
757+
IF_LOG_ENABLED({
758758
PHASAR_LOG_LEVEL(DEBUG,
759759
"Function : " << ICF->getFunctionOf(NHashN)->getName());
760760
PHASAR_LOG_LEVEL(DEBUG, "Inst. : " << IDEProblem.NtoString(NHashN));
761761
PHASAR_LOG_LEVEL(DEBUG, "Fact : " << IDEProblem.DtoString(NHashD));
762762
PHASAR_LOG_LEVEL(DEBUG, "Value : " << IDEProblem.LtoString(L));
763763
PHASAR_LOG_LEVEL(DEBUG, ' ');
764-
}());
764+
});
765765
// TOP is the implicit default value which we do not need to store.
766766
// if (l == IDEProblem.topElement()) {
767767
// do not store top values

include/phasar/PhasarLLVM/DataFlowSolver/Mono/CallString.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <iterator>
2424
#include <stdexcept>
2525

26+
#include "llvm/ADT/STLExtras.h"
2627
#include "llvm/Support/raw_ostream.h"
2728

2829
namespace psr {
@@ -40,38 +41,46 @@ template <typename T, unsigned K> class CallString {
4041
"initial call string length exceeds maximal length K");
4142
}
4243
}
44+
4345
void push(T S) {
4446
if (CS.size() > KLimit - 1) {
4547
CS.pop_front();
4648
}
4749
CS.push_back(S);
4850
}
51+
4952
T returnSite() {
5053
if (!CS.empty()) {
5154
return CS.back();
5255
}
5356
return {};
5457
}
58+
5559
void pop() {
5660
if (!CS.empty()) {
5761
CS.pop_back();
5862
}
5963
}
64+
6065
size_t size() { return CS.size(); }
66+
6167
std::deque<T> getInternalCS() const { return CS; }
68+
6269
friend bool operator==(const CallString &Lhs, const CallString &Rhs) {
6370
return Lhs.cs == Rhs.cs;
6471
}
72+
6573
friend bool operator!=(const CallString &Lhs, const CallString &Rhs) {
6674
return !(Lhs == Rhs);
6775
}
76+
6877
friend bool operator<(const CallString &Lhs, const CallString &Rhs) {
6978
return Lhs.cs < Rhs.cs;
7079
}
80+
7181
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
7282
const CallString &C) {
73-
std::copy(C.CS.begin(), --C.CS.end(), std::ostream_iterator<T>(OS, " * "));
74-
OS << C.CS.back();
83+
llvm::interleave(C.CS, OS, " * ");
7584
return OS;
7685
}
7786
};

include/phasar/Utils/Logger.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
/******************************************************************************
2-
* Copyright (c) 2017 Philipp Schubert.
2+
* Copyright (c) 2022 Philipp Schubert.
33
* All rights reserved. This program and the accompanying materials are made
44
* available under the terms of LICENSE.txt.
55
*
66
* Contributors:
7-
* Philipp Schubert and others
7+
* Martin Mory, Philipp Schubert and others
88
*****************************************************************************/
99

10-
/*
11-
* Logger.h
12-
*
13-
* Created on: 27.07.2017
14-
* Author: philipp
15-
*/
16-
17-
#ifndef PHASAR_UTILS_LOGGER_H_
18-
#define PHASAR_UTILS_LOGGER_H_
10+
#ifndef PHASAR_UTILS_LOGGER_H
11+
#define PHASAR_UTILS_LOGGER_H
1912

2013
#include <map>
2114
#include <optional>
@@ -104,20 +97,23 @@ class Logger final {
10497

10598
#define PHASAR_LOG_LEVEL(level, message) \
10699
IF_LOG_ENABLED_BOOL( \
107-
Logger::isLoggingEnabled() && level >= Logger::getLoggerFilterLevel(), \
100+
Logger::isLoggingEnabled() && (level) >= Logger::getLoggerFilterLevel(), \
108101
do { \
109102
auto &S = Logger::getLogStream(level, std::nullopt); \
110103
Logger::addLinePrefix(S, level, std::nullopt); \
104+
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
111105
S << message << '\n'; \
112106
} while (false);)
113107

114108
#define PHASAR_LOG_LEVEL_CAT(level, cat, message) \
115109
IF_LOG_ENABLED_BOOL( \
116-
Logger::isLoggingEnabled() && level >= Logger::getLoggerFilterLevel() && \
110+
Logger::isLoggingEnabled() && \
111+
(level) >= Logger::getLoggerFilterLevel() && \
117112
Logger::logCategory(cat, level), \
118113
do { \
119114
auto &S = Logger::getLogStream(level, cat); \
120115
Logger::addLinePrefix(S, level, cat); \
116+
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
121117
S << message << '\n'; \
122118
} while (false);)
123119

@@ -127,6 +123,7 @@ class Logger final {
127123
do { \
128124
auto &S = Logger::getLogStream(std::nullopt, cat); \
129125
Logger::addLinePrefix(S, std::nullopt, cat); \
126+
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
130127
S << message << '\n'; \
131128
} while (false);)
132129

@@ -139,7 +136,7 @@ class Logger final {
139136
computation; \
140137
}
141138

142-
// #define LOG_IF_ENABLE(computation) \
139+
// #define LOG_IF_ENABLE(computation) \
143140
// IF_LOG_ENABLED_BOOL(Logger::isLoggingEnabled(), computation)
144141

145142
#define IF_LOG_ENABLED(computation) \

lib/PhasarLLVM/Plugins/AnalysisPluginController.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
* Philipp Schubert and others
88
*****************************************************************************/
99

10-
#include <iostream>
11-
1210
#include "boost/dll.hpp"
1311

1412
#include "llvm/Support/ErrorHandling.h"
13+
#include "llvm/Support/raw_ostream.h"
1514

1615
#include "phasar/DB/ProjectIRDB.h"
1716
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"

0 commit comments

Comments
 (0)