Skip to content

Commit 0024a53

Browse files
mxHuberfabianbs96
andauthored
SourceCode-based IFDS/IDE UnitTests (#789)
* Add utility function to aid src-code based unittests * half of xtaint test, stuck on 12 * Fixed all but 09 and 12 * fixed all enabled ext taint tests * reworked test structure * refractor + more tests. Weird errors * debug commit * Fix psr::getDILocation() * std::variant for SrcCodeLocationEntry * bug fixed + ext taint test works * compile tests as dbg + ground truths * Fix Gt for UninitTest_02_SHOULD_LEAK * Add TestingSrcLocation * GLCA nearly done, questions for meeting * taint double free tests fail * Fixed IFDSConstAnalysisTest * fixed tainttest and segfaults + refactoring * Fix AnalysisPrinterTest * Convert AnalysisPrinterTest to src-code-based ground-truth * Start converting InstInterationAnalysis tests * Convert some more IIA test cases * Add more IIA tests * Convert FIIA-test + fix use-after-free in IIA test * HandleTypeState_03 not working * All but three fileio tests work * UninitVarTest fixed all but one * fixed all but 03 of TSAnalysisFile * Fixed all but one test * Fixed UninitTest_21 * Enable modeling of instruction-operands in TestingSrcLocation + fix 20th uninit test * reworked test 06 * cleanup * readded LIBCPP_GTEST_SKIP * fixed use after scope in taint analysis test * Make IDEExtendedTaintAnalysisTest more compact * Convert IIAFlowFact tests +make GLCA test more compact * Refactor rest of IfdsIde tests * Move everything in SrcCodeLocationEntry to psr::unittest + some cleanup * Some cleanup --------- Co-authored-by: Fabian Schiebel <fabian.schiebel@iem.fraunhofer.de> Co-authored-by: Fabian Schiebel <fabianbs@mail.upb.de>
1 parent 501c7e3 commit 0024a53

33 files changed

+3143
-1699
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ CheckOptions:
6161
- key: readability-identifier-naming.ParameterIgnoredRegexp
6262
value: (d|d1|d2|d3|d4|d5|eP|f|n)
6363
- key: readability-identifier-naming.FunctionIgnoredRegexp
64-
value: (try_emplace|from_json|to_json|equal_to|to_string|DToString|NToString|FToString|LToString|hash_value)
64+
value: (try_emplace|from_json|to_json|equal_to|to_string|DToString|NToString|FToString|LToString|hash_value|dyn_cast)
6565
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
6666
value: 1
6767
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions

include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ class IDESolver
16161616
} else {
16171617
// Get the fact-ID
16181618
D1FactId = G.getFactID(D1Fact);
1619-
std::string D1Label = DToString(D1Fact);
1619+
std::string D1Label{DToString(D1Fact)};
16201620

16211621
// Get or create the fact subgraph
16221622
D1FSG = FG->getOrCreateFactSG(D1FactId, D1Label);
@@ -1634,7 +1634,7 @@ class IDESolver
16341634
if (!IDEProblem.isZeroValue(D2Fact)) {
16351635
// Get the fact-ID
16361636
D2FactId = G.getFactID(D2Fact);
1637-
std::string D2Label = DToString(D2Fact);
1637+
std::string D2Label{DToString(D2Fact)};
16381638
DOTNode D2 = {FuncName, D2Label, N2StmtId, D2FactId, false, true};
16391639
std::string EFLabel;
16401640
auto EFVec = IntermediateEdgeFunctions[std::make_tuple(
@@ -1719,7 +1719,7 @@ class IDESolver
17191719
} else {
17201720
// Get the fact-ID
17211721
D1FactId = G.getFactID(D1Fact);
1722-
std::string D1Label = DToString(D1Fact);
1722+
std::string D1Label{DToString(D1Fact)};
17231723
D1 = {FNameOfN1, D1Label, N1StmtId, D1FactId, false, true};
17241724
// FG should already exist even for single statement functions
17251725
if (!G.containsFactSG(FNameOfN1, D1FactId)) {
@@ -1738,7 +1738,7 @@ class IDESolver
17381738
} else {
17391739
// Get the fact-ID
17401740
D2FactId = G.getFactID(D2Fact);
1741-
std::string D2Label = DToString(D2Fact);
1741+
std::string D2Label{DToString(D2Fact)};
17421742
D2 = {FNameOfN2, D2Label, N2StmtId, D2FactId, false, true};
17431743
// FG should already exist even for single statement functions
17441744
if (!G.containsFactSG(FNameOfN2, D2FactId)) {

include/phasar/Domain/LatticeDomain.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define PHASAR_DOMAIN_LATTICEDOMAIN_H
1212

1313
#include "phasar/Utils/ByRef.h"
14+
#include "phasar/Utils/DebugOutput.h"
1415
#include "phasar/Utils/JoinLattice.h"
1516
#include "phasar/Utils/TypeTraits.h"
1617

@@ -100,9 +101,7 @@ struct LatticeDomain : public std::variant<Top, L, Bottom> {
100101
}
101102
};
102103

103-
template <typename L,
104-
typename = std::void_t<decltype(std::declval<llvm::raw_ostream &>()
105-
<< std::declval<L>())>>
104+
template <typename L>
106105
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
107106
const LatticeDomain<L> &LD) {
108107
if (LD.isBottom()) {
@@ -114,7 +113,11 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
114113

115114
const auto *Val = LD.getValueOrNull();
116115
assert(Val && "Only alternative remaining is L");
117-
return OS << *Val;
116+
if constexpr (is_llvm_printable_v<L>) {
117+
return OS << *Val;
118+
} else {
119+
return OS << PrettyPrinter{*Val};
120+
}
118121
}
119122

120123
template <typename L>

include/phasar/Utils/BitVectorSet.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ class BitVectorSet {
292292

293293
[[nodiscard]] size_t size() const noexcept { return Bits.count(); }
294294

295-
[[nodiscard]] const BitVectorTy &getBits() const &noexcept { return Bits; }
296-
[[nodiscard]] BitVectorTy &getBits() &noexcept { return Bits; }
297-
[[nodiscard]] BitVectorTy &&getBits() &&noexcept { return std::move(Bits); }
295+
[[nodiscard]] const BitVectorTy &getBits() const & noexcept { return Bits; }
296+
[[nodiscard]] BitVectorTy &getBits() & noexcept { return Bits; }
297+
[[nodiscard]] BitVectorTy &&getBits() && noexcept { return std::move(Bits); }
298298

299299
friend bool operator==(const BitVectorSet &Lhs, const BitVectorSet &Rhs) {
300300
bool LeftEmpty = Lhs.empty();
@@ -392,6 +392,11 @@ class BitVectorSet {
392392
EndIter.setBits(Bits);
393393
return EndIter;
394394
}
395+
396+
static void clearPosition() {
397+
Position.left.clear();
398+
Position.right.clear();
399+
}
395400
};
396401

397402
// Overloads with the other intersectWith functions from Utilities.h

lib/PhasarLLVM/Utils/LLVMIRToSrc.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ static llvm::DISubprogram *getDISubprogram(const llvm::Value *V) {
101101

102102
llvm::DILocation *psr::getDILocation(const llvm::Value *V) {
103103
// Arguments and Instruction such as AllocaInst
104-
if (auto *DbgIntr = getDbgVarIntrinsic(V)) {
105-
if (auto *MN = DbgIntr->getMetadata(llvm::LLVMContext::MD_dbg)) {
104+
105+
if (const auto *I = llvm::dyn_cast<llvm::Instruction>(V)) {
106+
if (auto *MN = I->getMetadata(llvm::LLVMContext::MD_dbg)) {
106107
return llvm::dyn_cast<llvm::DILocation>(MN);
107108
}
108-
} else if (const auto *I = llvm::dyn_cast<llvm::Instruction>(V)) {
109-
if (auto *MN = I->getMetadata(llvm::LLVMContext::MD_dbg)) {
109+
}
110+
111+
if (auto *DbgIntr = getDbgVarIntrinsic(V)) {
112+
if (auto *MN = DbgIntr->getMetadata(llvm::LLVMContext::MD_dbg)) {
110113
return llvm::dyn_cast<llvm::DILocation>(MN);
111114
}
112115
}
116+
113117
return nullptr;
114118
}
115119

test/llvm_test_code/general_linear_constant/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ set(Sources
1414
)
1515

1616
foreach(TEST_SRC ${Sources})
17-
generate_ll_file(FILE ${TEST_SRC})
17+
generate_ll_file(FILE ${TEST_SRC} DEBUG)
1818
endforeach(TEST_SRC)

test/llvm_test_code/general_linear_constant/NullTest.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ char *foo(char *str) { return str; }
22

33
extern void puts(const char *);
44

5-
int main() { puts(foo(0)); }
5+
int main() {
6+
puts(foo(0));
7+
return 0;
8+
}

test/llvm_test_code/inst_interaction/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ set(SourcesOpt
4141
)
4242

4343
foreach(TEST_SRC ${Sources})
44-
generate_ll_file(FILE ${TEST_SRC})
44+
generate_ll_file(FILE ${TEST_SRC} DEBUG)
4545
endforeach(TEST_SRC)
4646

4747
foreach(TEST_SRC ${SourcesOpt})
48-
generate_ll_file(FILE ${TEST_SRC} O1)
48+
generate_ll_file(FILE ${TEST_SRC} DEBUG O1)
4949
endforeach(TEST_SRC)

test/llvm_test_code/openssl/key_derivation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ file(GLOB openssl_files *.c *.cpp)
22

33
foreach(TEST_SRC ${openssl_files})
44
get_filename_component(TEST_SRC_FILE ${TEST_SRC} NAME)
5-
generate_ll_file(FILE ${TEST_SRC_FILE})
5+
generate_ll_file(FILE ${TEST_SRC_FILE} DEBUG)
66
endforeach(TEST_SRC)

test/llvm_test_code/openssl/secure_heap/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ file(GLOB openssl_files *.c *.cpp)
22

33
foreach(TEST_SRC ${openssl_files})
44
get_filename_component(TEST_SRC_FILE ${TEST_SRC} NAME)
5-
generate_ll_file(FILE ${TEST_SRC_FILE})
5+
generate_ll_file(FILE ${TEST_SRC_FILE} DEBUG)
66
endforeach(TEST_SRC)

0 commit comments

Comments
 (0)