Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix #132

Merged
merged 2 commits into from
Oct 7, 2023
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
19 changes: 11 additions & 8 deletions lib/Core/ExecutionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ ExecutionState::ExecutionState()
depth(0), ptreeNode(nullptr), symbolics(), steppedInstructions(0),
steppedMemoryInstructions(0), instsSinceCovNew(0),
roundingMode(llvm::APFloat::rmNearestTiesToEven), coveredNew({}),
forkDisabled(false), prevHistory_(TargetsHistory::create()),
coveredNewError(new box<bool>(false)), forkDisabled(false),
prevHistory_(TargetsHistory::create()),
history_(TargetsHistory::create()) {
setID();
}
Expand All @@ -131,7 +132,8 @@ ExecutionState::ExecutionState(KFunction *kf)
depth(0), ptreeNode(nullptr), symbolics(), steppedInstructions(0),
steppedMemoryInstructions(0), instsSinceCovNew(0),
roundingMode(llvm::APFloat::rmNearestTiesToEven), coveredNew({}),
forkDisabled(false), prevHistory_(TargetsHistory::create()),
coveredNewError(new box<bool>(false)), forkDisabled(false),
prevHistory_(TargetsHistory::create()),
history_(TargetsHistory::create()) {
pushFrame(nullptr, kf);
setID();
Expand All @@ -142,7 +144,8 @@ ExecutionState::ExecutionState(KFunction *kf, KBlock *kb)
depth(0), ptreeNode(nullptr), symbolics(), steppedInstructions(0),
steppedMemoryInstructions(0), instsSinceCovNew(0),
roundingMode(llvm::APFloat::rmNearestTiesToEven), coveredNew({}),
forkDisabled(false), prevHistory_(TargetsHistory::create()),
coveredNewError(new box<bool>(false)), forkDisabled(false),
prevHistory_(TargetsHistory::create()),
history_(TargetsHistory::create()) {
pushFrame(nullptr, kf);
setID();
Expand Down Expand Up @@ -170,11 +173,11 @@ ExecutionState::ExecutionState(const ExecutionState &state)
unwindingInformation(state.unwindingInformation
? state.unwindingInformation->clone()
: nullptr),
coveredNew(state.coveredNew), forkDisabled(state.forkDisabled),
returnValue(state.returnValue), gepExprBases(state.gepExprBases),
prevTargets_(state.prevTargets_), targets_(state.targets_),
prevHistory_(state.prevHistory_), history_(state.history_),
isTargeted_(state.isTargeted_) {
coveredNew(state.coveredNew), coveredNewError(state.coveredNewError),
forkDisabled(state.forkDisabled), returnValue(state.returnValue),
gepExprBases(state.gepExprBases), prevTargets_(state.prevTargets_),
targets_(state.targets_), prevHistory_(state.prevHistory_),
history_(state.history_), isTargeted_(state.isTargeted_) {
queryMetaData.id = state.id;
}

Expand Down
9 changes: 8 additions & 1 deletion lib/Core/ExecutionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ class ExecutionState {

/// @brief Whether a new instruction was covered in this state
mutable std::deque<ref<box<bool>>> coveredNew;
mutable ref<box<bool>> coveredNewError;

/// @brief Disables forking for this state. Set by user code
bool forkDisabled = false;
Expand Down Expand Up @@ -507,7 +508,12 @@ class ExecutionState {
bool isCoveredNew() const {
return !coveredNew.empty() && coveredNew.back()->value;
}
void coverNew() const { coveredNew.push_back(new box<bool>(true)); }
bool isCoveredNewError() const { return coveredNewError->value; }
void coverNew() const {
coveredNew.push_back(new box<bool>(true));
coveredNewError->value = false;
coveredNewError = new box<bool>(true);
}
void updateCoveredNew() const {
while (!coveredNew.empty() && !coveredNew.front()->value) {
coveredNew.pop_front();
Expand All @@ -519,6 +525,7 @@ class ExecutionState {
}
coveredNew.clear();
}
void clearCoveredNewError() const { coveredNewError->value = false; }
};

struct ExecutionStateIDCompare {
Expand Down
8 changes: 5 additions & 3 deletions lib/Core/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4355,9 +4355,9 @@ void Executor::initializeTypeManager() {
typeSystemManager->initModule();
}

static bool shouldWriteTest(const ExecutionState &state) {
static bool shouldWriteTest(const ExecutionState &state, bool isError = false) {
state.updateCoveredNew();
bool coveredNew = state.isCoveredNew();
bool coveredNew = isError ? state.isCoveredNewError() : state.isCoveredNew();
return !OnlyOutputStatesCoveringNew || coveredNew;
}

Expand Down Expand Up @@ -4721,7 +4721,7 @@ void Executor::terminateStateOnError(ExecutionState &state,

if ((EmitAllErrors ||
emittedErrors.insert(std::make_pair(lastInst, message)).second) &&
shouldWriteTest(state)) {
shouldWriteTest(state, true)) {
std::string filepath = ki->getSourceFilepath();
if (!filepath.empty()) {
klee_message("ERROR: %s:%zu: %s", filepath.c_str(), ki->getLine(),
Expand Down Expand Up @@ -4752,6 +4752,8 @@ void Executor::terminateStateOnError(ExecutionState &state,
if (!info_str.empty())
msg << "Info: \n" << info_str;

state.clearCoveredNewError();

const std::string ext = terminationTypeFileExtension(terminationType);
// use user provided suffix from klee_report_error()
const char *file_suffix = suffix ? suffix : ext.c_str();
Expand Down
3 changes: 1 addition & 2 deletions test/Feature/LazyInitialization/DerefSymbolicPointer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm %O0opt -c -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --write-kqueries --output-dir=%t.klee-out --solver-backend=z3 --skip-not-symbolic-objects %t.bc > %t.log
// RUN: %klee --write-kqueries --output-dir=%t.klee-out --skip-not-symbolic-objects %t.bc > %t.log
// RUN: FileCheck %s -input-file=%t.log
#include "klee/klee.h"

Expand Down
3 changes: 1 addition & 2 deletions test/Feature/LazyInitialization/ImpossibleAddressForLI.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm -g -c -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --solver-backend=z3 --skip-not-symbolic-objects %t.bc 2>&1 | FileCheck %s
// RUN: %klee --output-dir=%t.klee-out --skip-not-symbolic-objects %t.bc 2>&1 | FileCheck %s

#include "klee/klee.h"

Expand Down
3 changes: 1 addition & 2 deletions test/Feature/LazyInitialization/LazyInitialization.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm %O0opt -c -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --solver-backend=z3 --skip-not-symbolic-objects --use-timestamps=false --use-guided-search=none %t.bc > %t.log
// RUN: %klee --output-dir=%t.klee-out --skip-not-symbolic-objects --use-timestamps=false --use-guided-search=none %t.bc > %t.log
// RUN: FileCheck %s -input-file=%t.log

struct Node {
Expand Down
3 changes: 1 addition & 2 deletions test/Feature/LazyInitialization/LinkedList.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm %O0opt -g -c -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --write-kqueries --solver-backend=z3 --output-dir=%t.klee-out --skip-not-symbolic-objects %t.bc > %t.log
// RUN: %klee --write-kqueries --output-dir=%t.klee-out --skip-not-symbolic-objects %t.bc > %t.log
// RUN: FileCheck %s -input-file=%t.log
#include "klee/klee.h"

Expand Down
3 changes: 1 addition & 2 deletions test/Feature/LazyInitialization/PointerOffset.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm %O0opt -c -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --solver-backend=z3 --skip-not-symbolic-objects --use-timestamps=false --skip-local=false %t.bc
// RUN: %klee --output-dir=%t.klee-out --skip-not-symbolic-objects --use-timestamps=false --skip-local=false %t.bc
// RUN: %ktest-tool %t.klee-out/test*.ktest > %t.log
// RUN: FileCheck %s -input-file=%t.log
// CHECK: pointers: [(0, 1, 4)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm -g -c -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --solver-backend=z3 --skip-not-symbolic-objects --skip-local=false --use-sym-size-li --min-number-elements-li=1 %t1.bc 2>&1 | FileCheck %s
// RUN: %klee --output-dir=%t.klee-out --skip-not-symbolic-objects --skip-local=false --use-sym-size-li --min-number-elements-li=1 %t1.bc 2>&1 | FileCheck %s

#include "klee/klee.h"
#include <assert.h>
Expand Down
3 changes: 1 addition & 2 deletions test/Feature/LazyInitialization/TwoObjectsInitialization.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm -g -c -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --solver-backend=z3 --skip-not-symbolic-objects %t1.bc 2>&1 | FileCheck %s
// RUN: %klee --output-dir=%t.klee-out --skip-not-symbolic-objects %t1.bc 2>&1 | FileCheck %s

#include "klee/klee.h"
#include <assert.h>
Expand Down
1 change: 0 additions & 1 deletion test/Industry/AssignNull_Scene_BadCase02.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void TestBad5(struct STU *pdev, const char *buf, unsigned int count)
printf("teacher id is %ud", teacherID);
}

// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --location-accuracy --mock-external-calls --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
Expand Down
1 change: 0 additions & 1 deletion test/Industry/AssignNull_Scene_BadCase04.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ int TestBad7(char *arg, unsigned int count)
return 1;
}

// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --mock-external-calls --check-out-of-memory --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --smart-resolve-entry-function --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
Expand Down
1 change: 0 additions & 1 deletion test/Industry/BadCase01_SecB_ForwardNull.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ void badbad(char *ptr)
}
#endif

// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --mock-external-calls --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --check-out-of-memory --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
Expand Down
1 change: 0 additions & 1 deletion test/Industry/CheckNull_Scene_BadCase02.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void TestBad2()
free(errMsg);
}

// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --mock-external-calls --check-out-of-memory --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
Expand Down
1 change: 0 additions & 1 deletion test/Industry/CheckNull_Scene_BadCase04.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void TestBad12(int cond1, int cond2)
}
}

// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --mock-external-calls --check-out-of-memory --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
Expand Down
12 changes: 6 additions & 6 deletions test/Industry/FN_SecB_ForwardNull_filed.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --mock-external-calls --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
// RUN: FileCheck -input-file=%t.klee-out/warnings.txt %s
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
* @description 空指针解引用 验收失败
Expand Down Expand Up @@ -44,8 +39,13 @@ void WB_BadCase_Field(UINT32 inputNum1, UINT32 inputNum2)
void WB_BadCase_field2(DataInfo *data)
{
data->dataBuff = NULL;
*data->dataBuff = 'c'; // CHECK: KLEE: WARNING: 100.00% NullPointerException False Negative at: {{.*}}test/Industry/FN_SecB_ForwardNull_filed.c:47 19
*data->dataBuff = 'c'; // CHECK: KLEE: WARNING: 100.00% NullPointerException False Negative at: {{.*}}test/Industry/FN_SecB_ForwardNull_filed.c:42 19

char *ptr = NULL;
*ptr = 'c'; // CHECK: KLEE: WARNING: 100.00% NullPointerException False Positive at trace 1
}

// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --use-guided-search=error --mock-external-calls --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
// RUN: FileCheck -input-file=%t.klee-out/warnings.txt %s
6 changes: 3 additions & 3 deletions test/Industry/FN_SecB_ForwardNull_filed.c.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"uri": "/mnt/d/wsl-ubuntu/test2/forward_null/./FN_SecB_ForwardNull_filed.c"
},
"region": {
"startLine": 49,
"startLine": 44,
"startColumn": null
}
}
Expand All @@ -33,7 +33,7 @@
"uri": "/mnt/d/wsl-ubuntu/test2/forward_null/./FN_SecB_ForwardNull_filed.c"
},
"region": {
"startLine": 50,
"startLine": 45,
"startColumn": null
}
}
Expand All @@ -52,7 +52,7 @@
"uri": "/mnt/d/wsl-ubuntu/test2/forward_null/./FN_SecB_ForwardNull_filed.c"
},
"region": {
"startLine": 50,
"startLine": 45,
"startColumn": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void call_func(int num)
ResourceLeak_bad01(num);
}

// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --write-kqueries --max-cycles-before-stuck=0 --use-guided-search=error --check-out-of-memory --mock-external-calls --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
Expand Down
10 changes: 5 additions & 5 deletions test/Industry/NullReturn_BadCase_WhiteBox01.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// REQUIRES: z3
// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --smart-resolve-entry-function --use-guided-search=error --mock-external-calls --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
// RUN: FileCheck -input-file=%t.klee-out/warnings.txt %s
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
*
Expand Down Expand Up @@ -68,3 +63,8 @@ void NullReturn_BadCase_WhiteBox01(UINT8 index, SchedHarqStru *harqInfo)
SendMsg(index, usrId, resultInfo); // (3)
}
}

// RUN: %clang %s -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --smart-resolve-entry-function --use-guided-search=error --mock-external-calls --libc=klee --skip-not-symbolic-objects --skip-not-lazy-initialized --use-lazy-initialization=only --analysis-reproduce=%s.json %t1.bc
// RUN: FileCheck -input-file=%t.klee-out/warnings.txt %s
Loading
Loading