Skip to content

Commit 1fa569f

Browse files
committed
sizeof(*(void*)) is sizeof(char)
1 parent d79067e commit 1fa569f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

regression/ansi-c/sizeof5/main.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define STATIC_ASSERT(condition) \
2+
int some_array##__LINE__[(condition) ? 1 : -1];
3+
4+
struct S
5+
{
6+
int x;
7+
};
8+
9+
int main()
10+
{
11+
struct S s;
12+
__typeof__(*((void *)&s.x)) *_s=&s.x;
13+
STATIC_ASSERT(sizeof(*_s)==1);
14+
return 0;
15+
}

regression/ansi-c/sizeof5/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/c_typecheck_expr.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,12 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
948948
throw 0;
949949
}
950950

951+
if(type.id()==ID_empty &&
952+
expr.operands().size()==1 &&
953+
expr.op0().id()==ID_dereference &&
954+
expr.op0().op0().type()==pointer_type(void_type()))
955+
type=char_type();
956+
951957
exprt new_expr=size_of_expr(type, *this);
952958

953959
if(new_expr.is_nil())

0 commit comments

Comments
 (0)