Skip to content

Commit

Permalink
sizeof(*(void*)) is sizeof(char)
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Sep 7, 2017
1 parent d79067e commit 1fa569f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions regression/ansi-c/sizeof5/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define STATIC_ASSERT(condition) \
int some_array##__LINE__[(condition) ? 1 : -1];

struct S
{
int x;
};

int main()
{
struct S s;
__typeof__(*((void *)&s.x)) *_s=&s.x;
STATIC_ASSERT(sizeof(*_s)==1);
return 0;
}
8 changes: 8 additions & 0 deletions regression/ansi-c/sizeof5/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
6 changes: 6 additions & 0 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,12 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
throw 0;
}

if(type.id()==ID_empty &&
expr.operands().size()==1 &&
expr.op0().id()==ID_dereference &&
expr.op0().op0().type()==pointer_type(void_type()))
type=char_type();

exprt new_expr=size_of_expr(type, *this);

if(new_expr.is_nil())
Expand Down

0 comments on commit 1fa569f

Please sign in to comment.