File tree 5 files changed +27
-19
lines changed
5 files changed +27
-19
lines changed Original file line number Diff line number Diff line change
1
+ #define STATIC_ASSERT (condition ) \
2
+ int some_array##__LINE__[(condition) ? 1 : -1];
3
+
4
+ STATIC_ASSERT ((void * )0 == (void * )(1 - 1 ));
5
+
6
+ int main ()
7
+ {
8
+ assert ((void * )0 == (void * )('a' - 'a' ));
9
+ return 0 ;
10
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --all-claims --no-simplify
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^\[main\.1\] assertion NULL == NULL: OK$
7
+ ^\*\* 0 of 1 failed (1 iterations)$
8
+ --
9
+ ^warning: ignoring
Original file line number Diff line number Diff line change 13
13
#include < util/std_expr.h>
14
14
#include < util/base_type.h>
15
15
#include < util/symbol.h>
16
+ #include < util/simplify_expr.h>
16
17
17
18
#include " c_typecast.h"
18
19
#include " c_types.h"
@@ -549,7 +550,7 @@ void c_typecastt::implicit_typecast_followed(
549
550
{
550
551
// special case: 0 == NULL
551
552
552
- if (expr.is_zero () && (
553
+ if (simplify_expr ( expr, ns) .is_zero () && (
553
554
src_type.id ()==ID_unsignedbv ||
554
555
src_type.id ()==ID_signedbv ||
555
556
src_type.id ()==ID_natural ||
Original file line number Diff line number Diff line change @@ -1179,7 +1179,7 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
1179
1179
1180
1180
// special case: NULL
1181
1181
if (expr_type.id ()==ID_pointer &&
1182
- op .is_zero ())
1182
+ simplify_expr (op, * this ) .is_zero ())
1183
1183
{
1184
1184
// zero typecasted to a pointer is NULL
1185
1185
constant_exprt result (ID_NULL, expr_type);
@@ -1400,31 +1400,18 @@ void c_typecheck_baset::typecheck_expr_rel(exprt &expr)
1400
1400
}
1401
1401
else
1402
1402
{
1403
- // pointer and zero
1404
- if (type0.id ()==ID_pointer && op1.is_zero ())
1405
- {
1406
- op1=constant_exprt (type0);
1407
- op1.set (ID_value, ID_NULL);
1408
- return ;
1409
- }
1410
-
1411
- if (type1.id ()==ID_pointer && op0.is_zero ())
1412
- {
1413
- op0=constant_exprt (type1);
1414
- op0.set (ID_value, ID_NULL);
1415
- return ;
1416
- }
1417
-
1418
1403
// pointer and integer
1419
1404
if (type0.id ()==ID_pointer && is_number (type1))
1420
1405
{
1421
1406
op1.make_typecast (type0);
1407
+ typecheck_expr_typecast (op1);
1422
1408
return ;
1423
1409
}
1424
1410
1425
1411
if (type1.id ()==ID_pointer && is_number (type0))
1426
1412
{
1427
1413
op0.make_typecast (type1);
1414
+ typecheck_expr_typecast (op0);
1428
1415
return ;
1429
1416
}
1430
1417
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ Module: C++ Language Type Checking
13
13
#include < util/expr_util.h>
14
14
#include < util/std_types.h>
15
15
#include < util/std_expr.h>
16
+ #include < util/simplify_expr.h>
16
17
17
18
#include < ansi-c/c_qualifiers.h>
18
19
#include < ansi-c/c_types.h>
@@ -560,7 +561,7 @@ bool cpp_typecheckt::standard_conversion_pointer(
560
561
return false ;
561
562
562
563
// integer 0 to NULL pointer conversion?
563
- if (expr.is_zero () &&
564
+ if (simplify_expr ( expr, * this ) .is_zero () &&
564
565
expr.type ().id ()!=ID_pointer)
565
566
{
566
567
new_expr = expr;
@@ -2088,7 +2089,7 @@ bool cpp_typecheckt::reinterpret_typecast(
2088
2089
&& !is_reference (type))
2089
2090
{
2090
2091
// integer to pointer
2091
- if (e .is_zero ())
2092
+ if (simplify_expr (e, * this ) .is_zero ())
2092
2093
{
2093
2094
// NULL
2094
2095
new_expr = e;
You can’t perform that action at this time.
0 commit comments