Skip to content

Commit ea2a087

Browse files
authored
Merge pull request #588 from secure-software-engineering/f-lca_swift_tests
F lca swift tests
2 parents 1d4e20a + 3e14211 commit ea2a087

61 files changed

Lines changed: 1390 additions & 27 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/phasar/PhasarLLVM/Utils/LLVMShorthands.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class LLVMProjectIRDB;
4848
*/
4949
bool isFunctionPointer(const llvm::Value *V) noexcept;
5050

51+
/**
52+
* @brief Checks if the given LLVM Type is a integer like struct.
53+
* @param V LLVM Type.
54+
* @return True, if given LLVM Type is a struct like this %TSi = type <{ i64 }>.
55+
* False, otherwise.
56+
*/
57+
bool isIntegerLikeType(const llvm::Type *T) noexcept;
58+
5159
/**
5260
* @brief Checks if the given LLVM Value is either a alloca instruction or a
5361
* heap allocation function, e.g. new, new[], malloc, realloc or calloc.

lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,12 @@ IDELinearConstantAnalysis::~IDELinearConstantAnalysis() {
287287
IDELinearConstantAnalysis::FlowFunctionPtrType
288288
IDELinearConstantAnalysis::getNormalFlowFunction(n_t Curr, n_t /*Succ*/) {
289289
if (const auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(Curr)) {
290-
if (Alloca->getAllocatedType()->isIntegerTy()) {
290+
auto *AT = Alloca->getAllocatedType();
291+
if (AT->isIntegerTy() || isIntegerLikeType(AT)) {
291292
return generateFromZero(Alloca);
292293
}
293294
}
295+
294296
// Check store instructions. Store instructions override previous value
295297
// of their pointer operand, i.e., kills previous fact (= pointer operand).
296298
if (const auto *Store = llvm::dyn_cast<llvm::StoreInst>(Curr)) {
@@ -487,7 +489,8 @@ IDELinearConstantAnalysis::getNormalEdgeFunction(n_t Curr, d_t CurrNode,
487489
if (const auto *Store = llvm::dyn_cast<llvm::StoreInst>(Curr)) {
488490
d_t PointerOperand = Store->getPointerOperand();
489491
d_t ValueOperand = Store->getValueOperand();
490-
if (PointerOperand == SuccNode) {
492+
if (PointerOperand == SuccNode ||
493+
PointerOperand->stripPointerCasts() == SuccNode) {
491494
// Case I: Storing a constant integer.
492495
if (isZeroValue(CurrNode) && llvm::isa<llvm::ConstantInt>(ValueOperand)) {
493496
PHASAR_LOG_LEVEL(DEBUG, "Case: Storing constant integer.");

lib/PhasarLLVM/Utils/LLVMShorthands.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ bool isFunctionPointer(const llvm::Value *V) noexcept {
6464
return false;
6565
}
6666

67+
bool isIntegerLikeType(const llvm::Type *T) noexcept {
68+
if (const auto *StructType = llvm::dyn_cast<llvm::StructType>(T)) {
69+
return StructType->isPacked() && StructType->elements().size() == 1 &&
70+
StructType->getElementType(0)->isIntegerTy();
71+
}
72+
return false;
73+
}
74+
6775
bool isAllocaInstOrHeapAllocaFunction(const llvm::Value *V) noexcept {
6876
if (V) {
6977
if (llvm::isa<llvm::AllocaInst>(V)) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var i = 13
5+
}
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var i = 13
5+
i = 17
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var i = 10
5+
var j = 14
6+
i = j
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var _ = addWrapper(14)
5+
}
6+
7+
static func addWrapper(_ x: Int) -> Int {
8+
var i = x
9+
var j = 20
10+
var k = i + j
11+
return k
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var _ = wrapper(3)
5+
}
6+
7+
static func wrapper(_ x: Int) -> Int {
8+
var i = x
9+
var j = 4 * i + 2
10+
return j
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var _ = wrapper(4)
5+
}
6+
7+
static func wrapper(_ x: Int) -> Int {
8+
var i = x
9+
i += 3 * 4
10+
return i
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@main
2+
struct MyMain {
3+
static func main() {
4+
var _ = wrapper(4)
5+
}
6+
7+
static func wrapper(_ x: Int) -> Int {
8+
var i = x
9+
var j = 3
10+
i += j * 4
11+
return i
12+
}
13+
}

0 commit comments

Comments
 (0)