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

[C++ Verification] fixed cpp if-else typecast #1692

Merged
merged 2 commits into from
Feb 21, 2024
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: 1 addition & 1 deletion regression/esbmc-cpp/cpp/ch2_5/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/cpp/cpp_stack_top_bug/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--k-induction-parallel
^VERIFICATION FAILED$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/cpp/llbmc_stack-test/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 2 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/deque/deque_empty/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/deque/deque_empty_bug/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 11 --no-unwinding-assertions --timeout 900
^VERIFICATION FAILED$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/stack/stack_empty_bug/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 15 --no-unwinding-assertions --timeout 900
^VERIFICATION FAILED$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/stack/stack_pop/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/stack/stack_pop_bug/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION FAILED$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/stack/stack_push_bug/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION FAILED$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/vector/ch11_16/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/vector/ch11_24/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/vector/ch21_10/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 10 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/vector/vector30/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 15 --no-unwinding-assertions --timeout 900
^VERIFICATION SUCCESSFUL$
2 changes: 1 addition & 1 deletion regression/esbmc-cpp/vector/vector50/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
--unwind 15 --no-unwinding-assertions --timeout 900
^VERIFICATION FAILED$
2 changes: 1 addition & 1 deletion regression/k-induction/cpp_stack_top_bug/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
THOROUGH
main.cpp
--k-induction
^VERIFICATION FAILED$
1 change: 1 addition & 0 deletions src/clang-c-frontend/clang_c_adjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class clang_c_adjust
adjust_function_call_arguments(side_effect_expr_function_callt &expr);
void do_special_functions(side_effect_expr_function_callt &expr);
void adjust_operands(exprt &expr);
virtual void adjust_if(exprt &expr);

/**
* methods for code (codet) adjustment
Expand Down
22 changes: 14 additions & 8 deletions src/clang-c-frontend/clang_c_adjust_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,7 @@ void clang_c_adjust::adjust_expr(exprt &expr)
}
else if (expr.id() == "if")
{
// Check all operands
adjust_operands(expr);

// If the condition is not of boolean type, it must be casted
gen_typecast(ns, expr.op0(), bool_type());

// Typecast both the true and false results
gen_typecast_arithmetic(ns, expr.op1(), expr.op2());
adjust_if(expr);
}
else if (expr.id() == "builtin_va_arg")
{
Expand Down Expand Up @@ -1332,6 +1325,19 @@ void clang_c_adjust::adjust_operands(exprt &expr)
adjust_expr(op);
}

void clang_c_adjust::adjust_if(exprt &expr)
{
// Check all operands
adjust_operands(expr);

// If the condition is not of boolean type, it must be casted
gen_typecast(ns, expr.op0(), bool_type());

// Typecast both the true and false results
// If the types are inconsistent
gen_typecast_arithmetic(ns, expr.op1(), expr.op2());
}

void clang_c_adjust::align_se_function_call_return_type(
exprt &,
side_effect_expr_function_callt &)
Expand Down
1 change: 1 addition & 0 deletions src/clang-cpp-frontend/clang_cpp_adjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class clang_cpp_adjust : public clang_c_adjust
void adjust_expr_rel(exprt &expr) override;
void adjust_new(exprt &expr);
void adjust_cpp_member(member_exprt &expr);
void adjust_if(exprt &expr) override;

/**
* methods for implicit GOTO code generation
Expand Down
17 changes: 16 additions & 1 deletion src/clang-cpp-frontend/clang_cpp_adjust_expr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <clang-c-frontend/typecast.h>
#include <clang-cpp-frontend/clang_cpp_adjust.h>
#include <util/c_sizeof.h>
#include <util/c_types.h>
#include <util/destructor.h>
#include <util/expr_util.h>

Expand Down Expand Up @@ -130,6 +132,19 @@ void clang_cpp_adjust::adjust_cpp_member(member_exprt &expr)
expr.swap(method_call);
}

void clang_cpp_adjust::adjust_if(exprt &expr)
{
// Check all operands
adjust_operands(expr);

// If the condition is not of boolean type, it must be casted
gen_typecast(ns, expr.op0(), bool_type());

// Typecast both the true and false results
gen_typecast(ns, expr.op1(), expr.type());
gen_typecast(ns, expr.op2(), expr.type());
}

void clang_cpp_adjust::adjust_side_effect_assign(side_effect_exprt &expr)
{
// sideeffect assign got be representing a binary operator
Expand Down Expand Up @@ -289,4 +304,4 @@ void clang_cpp_adjust::align_se_function_call_return_type(
const typet &return_type = (typet &)f_op.type().return_type();
if (return_type.id() != "constructor")
expr.type() = return_type;
}
}
Loading