Skip to content

Commit 0af9689

Browse files
authored
Merge pull request #5689 from tautschnig/pointer-simpl
Simplification of pointer comparison: do not assume numeric types
2 parents 92ef21e + a353fbb commit 0af9689

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// #include <string.h> is intentionally missing
2+
3+
struct c
4+
{
5+
};
6+
7+
int d()
8+
{
9+
struct c e;
10+
memcpy(e);
11+
}
12+
int main()
13+
{
14+
int (*h)() = d;
15+
h();
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
function 'memcpy' is not declared
5+
parameter "memcpy::dst" type mismatch
6+
^EXIT=6$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
Invariant check failed

src/util/simplify_expr_int.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,14 +1645,19 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
16451645
}
16461646
}
16471647
else if(
1648-
expr.op0().id() == ID_typecast &&
1649-
expr.op0().type().id() == ID_pointer &&
1650-
(to_typecast_expr(expr.op0()).op().type().id() == ID_pointer ||
1651-
config.ansi_c.NULL_is_zero))
1648+
expr.op0().id() == ID_typecast && expr.op0().type().id() == ID_pointer)
16521649
{
1650+
exprt op = to_typecast_expr(expr.op0()).op();
1651+
if(
1652+
op.type().id() != ID_pointer &&
1653+
(!config.ansi_c.NULL_is_zero || !is_number(op.type()) ||
1654+
op.type().id() == ID_complex))
1655+
{
1656+
return unchanged(expr);
1657+
}
1658+
16531659
// (type)ptr == NULL -> ptr == NULL
16541660
// note that 'ptr' may be an integer
1655-
exprt op = to_typecast_expr(expr.op0()).op();
16561661
auto new_expr = expr;
16571662
new_expr.op0().swap(op);
16581663
if(new_expr.op0().type().id() != ID_pointer)

0 commit comments

Comments
 (0)