Skip to content

Commit 674a8f0

Browse files
committed
Visual Studio rejects pointer arithmetic and dereferencing of void*
Pointer arithmetic using void* is a (document) GCC extension. Dereferencing void* pointers is permitted by GCC when the value is unused. Visual Studio rejects both. This required updates to tests to either not rely on pointer arithmetic over void*, or restrict tests to GCC only. Fixes: #5275
1 parent 12ef9e7 commit 674a8f0

File tree

17 files changed

+64
-15
lines changed

17 files changed

+64
-15
lines changed

regression/ansi-c/sizeof5/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=0$

regression/cbmc-cpp/Function_Arguments1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.cpp
33

44
^EXIT=0$

regression/cbmc/null6/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void *guard_malloc_counter = 0;
1+
char *guard_malloc_counter = 0;
22

33
void *my_malloc(int size)
44
{

regression/cbmc/ptr_arithmetic_on_null/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^\[main.assertion.1\] line .* assertion \(void \*\)0 != \(void \*\)0 \+ \(.*\)1: SUCCESS$

regression/cbmc/void_pointer1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/cbmc/void_pointer2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--pointer-check --no-simplify --unwind 3
44
^EXIT=0$

regression/cbmc/void_pointer3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-smt-backend gcc-only
22
main.c
33

44
^EXIT=0$

regression/cbmc/void_pointer5/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-smt-backend gcc-only
22
main.c
33

44
^EXIT=10$

regression/cbmc/void_pointer6/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--pointer-check
44
^EXIT=10$

regression/cbmc/void_pointer7/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/contracts/assigns_enforce_conditional_void_target/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--enforce-contract foo
4-
^.* error: void-typed expressions not allowed as assigns clause targets$
4+
^.* error: (void-typed expressions not allowed as assigns clause targets|dereferencing void pointer)$
55
^CONVERSION ERROR$
66
^EXIT=(1|64)$
77
^SIGNAL=0$

regression/contracts/assigns_enforce_conditional_void_target_list/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--enforce-contract foo
4-
^.* error: void-typed expressions not allowed as assigns clause targets$
4+
^.* error: (void-typed expressions not allowed as assigns clause targets|dereferencing void pointer)$
55
^CONVERSION ERROR$
66
^EXIT=(1|64)$
77
^SIGNAL=0$

regression/contracts/assigns_enforce_side_effects_1/test.desc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
CORE
22
main.c
33
--enforce-contract foo
4-
^.*error: void-typed expressions not allowed as assigns clause targets$
5-
^.*error: side-effects not allowed in assigns clause targets$
6-
^.*error: ternary expressions not allowed in assigns clause targets$
4+
activate-multi-line-match
5+
.*error: (dereferencing void pointer|void-typed expressions not allowed as assigns clause targets\n.*\n.*error: side-effects not allowed in assigns clause targets\n.*\n.*error: ternary expressions not allowed in assigns clause targets\n)
76
^CONVERSION ERROR$
87
^EXIT=(1|64)$
98
^SIGNAL=0$
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void *malloc(__CPROVER_size_t);
2+
int printf(const char *, ...);
3+
4+
int main(int argc, char *argv[])
5+
{
6+
void *p = malloc(2);
7+
printf("%p\n", p);
8+
#ifdef VOID1
9+
(void)*p;
10+
#else
11+
void *q = &p[1];
12+
printf("%p\n", q);
13+
#endif
14+
return 0;
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
error: pointer arithmetic with unknown object size
5+
^CONVERSION ERROR$
6+
^EXIT=(64|1)$
7+
^SIGNAL=0$
8+
--
9+
Invariant check failed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
-DVOID1
4+
error: dereferencing void pointer
5+
^CONVERSION ERROR$
6+
^EXIT=(64|1)$
7+
^SIGNAL=0$
8+
--
9+
Invariant check failed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,15 @@ void c_typecheck_baset::typecheck_expr_dereference(exprt &expr)
17841784
else if(op_type.id()==ID_pointer)
17851785
{
17861786
expr.type() = to_pointer_type(op_type).base_type();
1787+
1788+
if(
1789+
expr.type().id() == ID_empty &&
1790+
config.ansi_c.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
1791+
{
1792+
error().source_location = expr.source_location();
1793+
error() << "dereferencing void pointer" << eom;
1794+
throw 0;
1795+
}
17871796
}
17881797
else
17891798
{
@@ -3718,6 +3727,14 @@ void c_typecheck_baset::typecheck_arithmetic_pointer(const exprt &expr)
37183727
error() << "pointer arithmetic with unknown object size" << eom;
37193728
throw 0;
37203729
}
3730+
else if(
3731+
base_type.id() == ID_empty &&
3732+
config.ansi_c.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
3733+
{
3734+
error().source_location = expr.source_location();
3735+
error() << "pointer arithmetic with unknown object size" << eom;
3736+
throw 0;
3737+
}
37213738
}
37223739

37233740
void c_typecheck_baset::typecheck_expr_pointer_arithmetic(exprt &expr)

0 commit comments

Comments
 (0)