Skip to content

Simplification of pointer comparison: do not assume numeric types #5689

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

Merged
merged 1 commit into from
Dec 25, 2020
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
16 changes: 16 additions & 0 deletions regression/cbmc-library/memcpy-06/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// #include <string.h> is intentionally missing

struct c
{
};

int d()
{
struct c e;
memcpy(e);
}
int main()
{
int (*h)() = d;
h();
}
10 changes: 10 additions & 0 deletions regression/cbmc-library/memcpy-06/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c

function 'memcpy' is not declared
parameter "memcpy::dst" type mismatch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ mixture of " and '

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there's some more work after #4875 left to be done. I'll create a separate PR for this.

^EXIT=6$
^SIGNAL=0$
--
^warning: ignoring
Invariant check failed
15 changes: 10 additions & 5 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,14 +1645,19 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
}
}
else if(
expr.op0().id() == ID_typecast &&
expr.op0().type().id() == ID_pointer &&
(to_typecast_expr(expr.op0()).op().type().id() == ID_pointer ||
config.ansi_c.NULL_is_zero))
expr.op0().id() == ID_typecast && expr.op0().type().id() == ID_pointer)
{
exprt op = to_typecast_expr(expr.op0()).op();
if(
op.type().id() != ID_pointer &&
(!config.ansi_c.NULL_is_zero || !is_number(op.type()) ||
op.type().id() == ID_complex))
{
return unchanged(expr);
}

// (type)ptr == NULL -> ptr == NULL
// note that 'ptr' may be an integer
exprt op = to_typecast_expr(expr.op0()).op();
auto new_expr = expr;
new_expr.op0().swap(op);
if(new_expr.op0().type().id() != ID_pointer)
Expand Down