Skip to content

Commit dbffea6

Browse files
authored
Merge pull request #8203 from tautschnig/bugfixes/follow-enum-tag
nondet-volatile: fix handling of enum types
2 parents 13236c7 + 4465a38 commit dbffea6

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

regression/goto-instrument/nondet-volatile-01/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include <assert.h>
22

3+
enum E
4+
{
5+
A,
6+
B
7+
};
8+
39
void main()
410
{
511
int a[2] = {0};
@@ -8,4 +14,8 @@ void main()
814
a[i] = 1;
915

1016
assert(a[1] == 0); // should fail
17+
18+
// make sure the use of enum (tags) does not cause infinite recursion
19+
enum A e = A;
20+
e = e;
1121
}

src/goto-instrument/nondet_volatile.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Date: September 2011
1313

1414
#include "nondet_volatile.h"
1515

16+
#include <util/c_types.h>
1617
#include <util/cmdline.h>
1718
#include <util/fresh_symbol.h>
1819
#include <util/options.h>
@@ -94,14 +95,14 @@ bool nondet_volatilet::is_volatile(const namespacet &ns, const typet &src)
9495
if(src.get_bool(ID_C_volatile))
9596
return true;
9697

97-
if(
98-
src.id() == ID_struct_tag || src.id() == ID_union_tag ||
99-
src.id() == ID_c_enum_tag)
100-
{
101-
return is_volatile(ns, ns.follow(src));
102-
}
103-
104-
return false;
98+
if(auto struct_tag = type_try_dynamic_cast<struct_tag_typet>(src))
99+
return is_volatile(ns, ns.follow_tag(*struct_tag));
100+
else if(auto union_tag = type_try_dynamic_cast<union_tag_typet>(src))
101+
return is_volatile(ns, ns.follow_tag(*union_tag));
102+
else if(auto enum_tag = type_try_dynamic_cast<c_enum_tag_typet>(src))
103+
return is_volatile(ns, ns.follow_tag(*enum_tag));
104+
else
105+
return false;
105106
}
106107

107108
void nondet_volatilet::handle_volatile_expression(

0 commit comments

Comments
 (0)