File tree 2 files changed +28
-16
lines changed
2 files changed +28
-16
lines changed Original file line number Diff line number Diff line change @@ -935,26 +935,30 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
935
935
throw 0 ;
936
936
}
937
937
938
+ exprt new_expr;
939
+
938
940
if (type.id ()==ID_c_bit_field)
939
941
{
940
942
err_location (expr);
941
943
error () << " sizeof cannot be applied to bit fields" << eom;
942
944
throw 0 ;
943
945
}
944
-
945
- if (type.id ()==ID_empty &&
946
- expr.operands ().size ()==1 &&
947
- expr.op0 ().id ()==ID_dereference &&
948
- expr.op0 ().op0 ().type ()==pointer_type (void_type ()))
949
- type=char_type ();
950
-
951
- exprt new_expr=size_of_expr (type, *this );
952
-
953
- if (new_expr.is_nil ())
946
+ else if (type.id () == ID_empty)
954
947
{
955
- err_location (expr);
956
- error () << " type has no size: " << to_string (type) << eom;
957
- throw 0 ;
948
+ // This is a gcc extension.
949
+ // https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
950
+ new_expr = size_of_expr (char_type (), *this );
951
+ }
952
+ else
953
+ {
954
+ new_expr = size_of_expr (type, *this );
955
+
956
+ if (new_expr.is_nil ())
957
+ {
958
+ err_location (expr);
959
+ error () << " type has no size: " << to_string (type) << eom;
960
+ throw 0 ;
961
+ }
958
962
}
959
963
960
964
new_expr.swap (expr);
Original file line number Diff line number Diff line change @@ -348,10 +348,18 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
348
348
CHECK_RETURN (bv.size ()==bits);
349
349
350
350
typet pointer_sub_type=it->type ().subtype ();
351
+
351
352
if (pointer_sub_type.id ()==ID_empty)
352
- pointer_sub_type=char_type ();
353
- size=pointer_offset_size (pointer_sub_type, ns);
354
- CHECK_RETURN (size>0 );
353
+ {
354
+ // This is a gcc extension.
355
+ // https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
356
+ size = 1 ;
357
+ }
358
+ else
359
+ {
360
+ size = pointer_offset_size (pointer_sub_type, ns);
361
+ CHECK_RETURN (size > 0 );
362
+ }
355
363
}
356
364
}
357
365
You can’t perform that action at this time.
0 commit comments