Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ CheckOptions:
value: (c|d|d1|d2|d3|d4|d5|d5_restoredCtx|eP|f|f3|f4|f5|fCalleeSummary|g|n|dPrime|fPrime)
- key: readability-identifier-naming.ParameterIgnoredRegexp
value: (d|d1|d2|d3|d4|d5|eP|f|n)
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: (try_emplace|from_json|to_json)
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
Expand Down
181 changes: 101 additions & 80 deletions include/phasar/PhasarLLVM/Domain/ExtendedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,159 +19,180 @@ namespace psr {

class ExtendedValue {
public:
ExtendedValue() {}
explicit ExtendedValue(const llvm::Value *_value) : value(_value) {
assert(value && "ExtendedValue requires an llvm::Value* object");
ExtendedValue() = default;
explicit ExtendedValue(const llvm::Value *Val) : Val(Val) {
assert(Val && "ExtendedValue requires an llvm::Value* object");
}
~ExtendedValue() = default;

bool operator==(const ExtendedValue &rhs) const {
bool isValueEqual = value == rhs.value;
if (!isValueEqual)
bool operator==(const ExtendedValue &Rhs) const {
bool IsValueEqual = Val == Rhs.Val;
if (!IsValueEqual) {
return false;
}

bool isMemLocationSeqEqual = memLocationSeq == rhs.memLocationSeq;
if (!isMemLocationSeqEqual)
bool IsMemLocationSeqEqual = MemLocationSeq == Rhs.MemLocationSeq;
if (!IsMemLocationSeqEqual) {
return false;
}

bool isEndOfTaintedBlockLabelEqual =
endOfTaintedBlockLabel == rhs.endOfTaintedBlockLabel;
if (!isEndOfTaintedBlockLabelEqual)
bool IsEndOfTaintedBlockLabelEqual =
EndOfTaintedBlockLabel == Rhs.EndOfTaintedBlockLabel;
if (!IsEndOfTaintedBlockLabelEqual) {
return false;
}

bool isVaListMemLocationSeqEqual =
vaListMemLocationSeq == rhs.vaListMemLocationSeq;
if (!isVaListMemLocationSeqEqual)
bool IsVaListMemLocationSeqEqual =
VaListMemLocationSeq == Rhs.VaListMemLocationSeq;
if (!IsVaListMemLocationSeqEqual) {
return false;
}

bool isVarArgIndexEqual = varArgIndex == rhs.varArgIndex;
if (!isVarArgIndexEqual)
bool IsVarArgIndexEqual = VarArgIndex == Rhs.VarArgIndex;
if (!IsVarArgIndexEqual) {
return false;
}

bool isCurrentVarArgIndexEqual =
currentVarArgIndex == rhs.currentVarArgIndex;
if (!isCurrentVarArgIndexEqual)
bool IsCurrentVarArgIndexEqual =
CurrentVarArgIndex == Rhs.CurrentVarArgIndex;
if (!IsCurrentVarArgIndexEqual) {
return false;
}

return true;
}

bool operator<(const ExtendedValue &rhs) const {
if (std::less<const llvm::Value *>{}(value, rhs.value))
bool operator<(const ExtendedValue &Rhs) const {
if (std::less<const llvm::Value *>{}(Val, Rhs.Val)) {
return true;
if (std::less<const llvm::Value *>{}(rhs.value, value))
}
if (std::less<const llvm::Value *>{}(Rhs.Val, Val)) {
return false;
}

if (memLocationSeq < rhs.memLocationSeq)
if (MemLocationSeq < Rhs.MemLocationSeq) {
return true;
if (rhs.memLocationSeq < memLocationSeq)
}
if (Rhs.MemLocationSeq < MemLocationSeq) {
return false;
}

if (std::less<std::string>{}(endOfTaintedBlockLabel,
rhs.endOfTaintedBlockLabel))
if (std::less<std::string>{}(EndOfTaintedBlockLabel,
Rhs.EndOfTaintedBlockLabel)) {
return true;
if (std::less<std::string>{}(rhs.endOfTaintedBlockLabel,
endOfTaintedBlockLabel))
}
if (std::less<std::string>{}(Rhs.EndOfTaintedBlockLabel,
EndOfTaintedBlockLabel)) {
return false;
}

if (vaListMemLocationSeq < rhs.vaListMemLocationSeq)
if (VaListMemLocationSeq < Rhs.VaListMemLocationSeq) {
return true;
if (rhs.vaListMemLocationSeq < vaListMemLocationSeq)
}
if (Rhs.VaListMemLocationSeq < VaListMemLocationSeq) {
return false;
}

if (std::less<long>{}(varArgIndex, rhs.varArgIndex))
if (std::less<long>{}(VarArgIndex, Rhs.VarArgIndex)) {
return true;
if (std::less<long>{}(rhs.varArgIndex, varArgIndex))
}
if (std::less<long>{}(Rhs.VarArgIndex, VarArgIndex)) {
return false;
}

return std::less<long>{}(currentVarArgIndex, rhs.currentVarArgIndex);
return std::less<long>{}(CurrentVarArgIndex, Rhs.CurrentVarArgIndex);
}

const llvm::Value *getValue() const { return value; }
[[nodiscard]] const llvm::Value *getValue() const { return Val; }

const std::vector<const llvm::Value *> getMemLocationSeq() const {
return memLocationSeq;
[[nodiscard]] std::vector<const llvm::Value *> getMemLocationSeq() const {
return MemLocationSeq;
}
void setMemLocationSeq(std::vector<const llvm::Value *> _memLocationSeq) {
memLocationSeq = _memLocationSeq;
void
setMemLocationSeq(const std::vector<const llvm::Value *> &MemLocationSeq) {
this->MemLocationSeq = MemLocationSeq;
}

const std::string getEndOfTaintedBlockLabel() const {
return endOfTaintedBlockLabel;
[[nodiscard]] std::string getEndOfTaintedBlockLabel() const {
return EndOfTaintedBlockLabel;
}
void setEndOfTaintedBlockLabel(std::string _endOfTaintedBlockLabel) {
endOfTaintedBlockLabel = _endOfTaintedBlockLabel;
void setEndOfTaintedBlockLabel(const std::string &EndOfTaintedBlockLabel) {
this->EndOfTaintedBlockLabel = EndOfTaintedBlockLabel;
}

const std::vector<const llvm::Value *> getVaListMemLocationSeq() const {
return vaListMemLocationSeq;
[[nodiscard]] std::vector<const llvm::Value *>
getVaListMemLocationSeq() const {
return VaListMemLocationSeq;
}
void setVaListMemLocationSeq(
std::vector<const llvm::Value *> _vaListMemLocationSeq) {
vaListMemLocationSeq = _vaListMemLocationSeq;
const std::vector<const llvm::Value *> &VaListMemLocationSeq) {
this->VaListMemLocationSeq = VaListMemLocationSeq;
}

long getVarArgIndex() const { return varArgIndex; }
void setVarArgIndex(long _varArgIndex) { varArgIndex = _varArgIndex; }
[[nodiscard]] long getVarArgIndex() const { return VarArgIndex; }
void setVarArgIndex(long VarArgIndex) { this->VarArgIndex = VarArgIndex; }

void resetVarArgIndex() {
if (!isVarArgTemplate())
varArgIndex = -1L;
if (!isVarArgTemplate()) {
VarArgIndex = -1L;
}
}

long getCurrentVarArgIndex() const { return currentVarArgIndex; }
[[nodiscard]] long getCurrentVarArgIndex() const {
return CurrentVarArgIndex;
}
void incrementCurrentVarArgIndex() {
if (!isVarArgTemplate())
++currentVarArgIndex;
if (!isVarArgTemplate()) {
++CurrentVarArgIndex;
}
}

bool isVarArgTemplate() const {
return vaListMemLocationSeq.empty() && isVarArg();
[[nodiscard]] bool isVarArg() const { return VarArgIndex > -1L; }
[[nodiscard]] bool isVarArgTemplate() const {
return VaListMemLocationSeq.empty() && isVarArg();
}

[[nodiscard]] bool isVarArg() const { return varArgIndex > -1L; }

private:
const llvm::Value *value = nullptr;
std::vector<const llvm::Value *> memLocationSeq;
std::string endOfTaintedBlockLabel;
const llvm::Value *Val = nullptr;
std::vector<const llvm::Value *> MemLocationSeq;
std::string EndOfTaintedBlockLabel;

std::vector<const llvm::Value *> vaListMemLocationSeq;
long varArgIndex = -1L;
long currentVarArgIndex = -1L;
std::vector<const llvm::Value *> VaListMemLocationSeq;
long VarArgIndex = -1L;
long CurrentVarArgIndex = -1L;
};

} // namespace psr

namespace std {

template <> struct hash<psr::ExtendedValue> {
std::size_t operator()(const psr::ExtendedValue &ev) const {
std::size_t seed = 0x4711;
std::size_t operator()(const psr::ExtendedValue &Ev) const {
std::size_t Seed = 0x4711;

seed ^= hash<const llvm::Value *>{}(ev.getValue()) + 0x9e3779b9 +
(seed << 6) + (seed >> 2);
Seed ^= hash<const llvm::Value *>{}(Ev.getValue()) + 0x9e3779b9 +
(Seed << 6) + (Seed >> 2);

for (const auto &memLocationPart : ev.getMemLocationSeq()) {
seed ^= hash<const llvm::Value *>{}(memLocationPart) + 0x9e3779b9 +
(seed << 6) + (seed >> 2);
for (const auto &MemLocationPart : Ev.getMemLocationSeq()) {
Seed ^= hash<const llvm::Value *>{}(MemLocationPart) + 0x9e3779b9 +
(Seed << 6) + (Seed >> 2);
}

seed ^= hash<string>{}(ev.getEndOfTaintedBlockLabel()) + 0x9e3779b9 +
(seed << 6) + (seed >> 2);
Seed ^= hash<string>{}(Ev.getEndOfTaintedBlockLabel()) + 0x9e3779b9 +
(Seed << 6) + (Seed >> 2);

for (const auto &vaListMemLocationPart : ev.getVaListMemLocationSeq()) {
seed ^= hash<const llvm::Value *>{}(vaListMemLocationPart) + 0x9e3779b9 +
(seed << 6) + (seed >> 2);
for (const auto &VaListMemLocationPart : Ev.getVaListMemLocationSeq()) {
Seed ^= hash<const llvm::Value *>{}(VaListMemLocationPart) + 0x9e3779b9 +
(Seed << 6) + (Seed >> 2);
}

seed ^= hash<long>{}(ev.getVarArgIndex()) + 0x9e3779b9 + (seed << 6) +
(seed >> 2);
Seed ^= hash<long>{}(Ev.getVarArgIndex()) + 0x9e3779b9 + (Seed << 6) +
(Seed >> 2);

seed ^= hash<long>{}(ev.getCurrentVarArgIndex()) + 0x9e3779b9 +
(seed << 6) + (seed >> 2);
Seed ^= hash<long>{}(Ev.getCurrentVarArgIndex()) + 0x9e3779b9 +
(Seed << 6) + (Seed >> 2);

return seed;
return Seed;
}
};

Expand Down
20 changes: 10 additions & 10 deletions include/phasar/PhasarLLVM/TaintConfig/TaintConfigUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void collectGeneratedFacts(ContainerTy &Dest, const TaintConfig &Config,
Dest.insert(CB);
}

for (unsigned i = 0, end = Callee->arg_size(); i < end; ++i) {
if (Config.isSource(Callee->getArg(i))) {
Dest.insert(CB->getArgOperand(i));
for (unsigned I = 0, End = Callee->arg_size(); I < End; ++I) {
if (Config.isSource(Callee->getArg(I))) {
Dest.insert(CB->getArgOperand(I));
}
}
}
Expand All @@ -58,9 +58,9 @@ void collectLeakedFacts(ContainerTy &Dest, const TaintConfig &Config,
std::inserter(Dest, Dest.end()), LeakIf);
}

for (unsigned i = 0, end = Callee->arg_size(); i < end; ++i) {
if (Config.isSink(Callee->getArg(i)) && LeakIf(CB->getArgOperand(i))) {
Dest.insert(CB->getArgOperand(i));
for (unsigned I = 0, End = Callee->arg_size(); I < End; ++I) {
if (Config.isSink(Callee->getArg(I)) && LeakIf(CB->getArgOperand(I))) {
Dest.insert(CB->getArgOperand(I));
}
}
}
Expand All @@ -70,7 +70,7 @@ inline void collectLeakedFacts(ContainerTy &Dest, const TaintConfig &Config,
const llvm::CallBase *CB,
const llvm::Function *Callee) {
collectLeakedFacts(Dest, Config, CB, Callee,
[](const llvm::Value *V) { return true; });
[](const llvm::Value * /*V*/) { return true; });
}

template <typename ContainerTy,
Expand All @@ -79,9 +79,9 @@ template <typename ContainerTy,
void collectSanitizedFacts(ContainerTy &Dest, const TaintConfig &Config,
const llvm::CallBase *CB,
const llvm::Function *Callee) {
for (unsigned i = 0, end = Callee->arg_size(); i < end; ++i) {
if (Config.isSanitizer(Callee->getArg(i))) {
Dest.insert(CB->getArgOperand(i));
for (unsigned I = 0, End = Callee->arg_size(); I < End; ++I) {
if (Config.isSanitizer(Callee->getArg(I))) {
Dest.insert(CB->getArgOperand(I));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion include/phasar/PhasarLLVM/Utils/BasicBlockOrdering.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class DefaultDominatorTreeAnalysis {
class BasicBlockOrdering {
/// Note: Cannot use std::function, because we need to support move-only
/// functors(e.g. DefaultDominatorTreeAnalysis)
llvm::unique_function<llvm::DominatorTree &(const llvm::Function *)> getDom;
llvm::unique_function<llvm::DominatorTree &(const llvm::Function *)>
getDom; // NOLINT

public:
template <
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarLLVM/Utils/BinaryDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern const std::map<std::string, BinaryDomain> StringToBinaryDomain;

extern const std::map<BinaryDomain, std::string> BinaryDomainToString;

std::ostream &operator<<(std::ostream &os, const BinaryDomain &b);
std::ostream &operator<<(std::ostream &OS, const BinaryDomain &B);

} // namespace psr

Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::string toString(const DataFlowAnalysisType &D);

DataFlowAnalysisType toDataFlowAnalysisType(const std::string &S);

std::ostream &operator<<(std::ostream &os, const DataFlowAnalysisType &D);
std::ostream &operator<<(std::ostream &OS, const DataFlowAnalysisType &D);

} // namespace psr

Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarLLVM/Utils/IOFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::string toString(const IOFormat &D);

IOFormat toIOFormat(const std::string &S);

std::ostream &operator<<(std::ostream &os, const IOFormat &D);
std::ostream &operator<<(std::ostream &Os, const IOFormat &D);

} // namespace psr

Expand Down
8 changes: 4 additions & 4 deletions include/phasar/PhasarLLVM/Utils/LatticeDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ inline bool operator==(const LatticeDomain<L> &Lhs,
std::holds_alternative<Bottom>(Rhs)) {
return true;
}
if (auto LhsPtr = std::get_if<L>(&Lhs)) {
if (auto RhsPtr = std::get_if<L>(&Rhs)) {
if (auto *LhsPtr = std::get_if<L>(&Lhs)) {
if (auto *RhsPtr = std::get_if<L>(&Rhs)) {
return *LhsPtr == *RhsPtr;
}
}
Expand All @@ -86,8 +86,8 @@ inline bool operator<(const LatticeDomain<L> &Lhs,
return true;
}

if (auto LhsPtr = std::get_if<L>(&Lhs)) {
if (auto RhsPtr = std::get_if<L>(&Rhs)) {
if (auto *LhsPtr = std::get_if<L>(&Lhs)) {
if (auto *RhsPtr = std::get_if<L>(&Rhs)) {
return *LhsPtr < *RhsPtr;
}
}
Expand Down
Loading