Skip to content

Commit 72f5736

Browse files
committed
dump-c: when removing const-ness, also handle bit fields
We need to remove the const qualifier when the assignment is no longer performed as part of the declaration. This worked for various types already, but bit fields had not been considered.
1 parent fd8af8a commit 72f5736

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

regression/goto-instrument/chain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ elif echo $args | grep -q -- "--dump-c-type-header" ; then
3838
cat "${name}-mod.gb"
3939
mv "${name}.gb" "${name}-mod.gb"
4040
elif echo $args | grep -q -- "--dump-c" ; then
41+
cat "${name}-mod.gb"
4142
mv "${name}-mod.gb" "${name}-mod.c"
4243

4344
if [[ "${is_windows}" == "true" ]]; then
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <assert.h>
2+
3+
struct S
4+
{
5+
const int x;
6+
const int y : 8;
7+
const int *const p;
8+
};
9+
10+
int foo()
11+
{
12+
return 1;
13+
}
14+
15+
int main()
16+
{
17+
struct S s1 = {foo(), 1, 0};
18+
assert(s1.x == 1);
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
signed int x
5+
signed int y
6+
const signed int \*p
7+
^[[:space:]]*s1 = \(struct S\)\{ .* \};
8+
^EXIT=0$
9+
^SIGNAL=0$
10+
--
11+
const signed int x
12+
const signed int y
13+
const p
14+
--
15+
This test demonstrates that the constness of struct members has been removed,
16+
which is necessary as the initialisation is not performed in the declaration.

src/goto-instrument/goto_program2code.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,8 @@ void goto_program2codet::remove_const(typet &type)
15911591
++it)
15921592
remove_const(it->type());
15931593
}
1594+
else if(type.id() == ID_c_bit_field)
1595+
to_c_bit_field_type(type).subtype().remove(ID_C_constant);
15941596
}
15951597

15961598
static bool has_labels(const codet &code)

0 commit comments

Comments
 (0)