Skip to content

nondet-volatile: fix handling of enum types #8203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions regression/goto-instrument/nondet-volatile-01/test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include <assert.h>

enum E
{
A,
B
};

void main()
{
int a[2] = {0};
Expand All @@ -8,4 +14,8 @@ void main()
a[i] = 1;

assert(a[1] == 0); // should fail

// make sure the use of enum (tags) does not cause infinite recursion
enum A e = A;
e = e;
}
17 changes: 9 additions & 8 deletions src/goto-instrument/nondet_volatile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Date: September 2011

#include "nondet_volatile.h"

#include <util/c_types.h>
#include <util/cmdline.h>
#include <util/fresh_symbol.h>
#include <util/options.h>
Expand Down Expand Up @@ -94,14 +95,14 @@ bool nondet_volatilet::is_volatile(const namespacet &ns, const typet &src)
if(src.get_bool(ID_C_volatile))
return true;

if(
src.id() == ID_struct_tag || src.id() == ID_union_tag ||
src.id() == ID_c_enum_tag)
{
return is_volatile(ns, ns.follow(src));
}

return false;
if(auto struct_tag = type_try_dynamic_cast<struct_tag_typet>(src))
return is_volatile(ns, ns.follow_tag(*struct_tag));
else if(auto union_tag = type_try_dynamic_cast<union_tag_typet>(src))
return is_volatile(ns, ns.follow_tag(*union_tag));
else if(auto enum_tag = type_try_dynamic_cast<c_enum_tag_typet>(src))
return is_volatile(ns, ns.follow_tag(*enum_tag));
else
return false;
}

void nondet_volatilet::handle_volatile_expression(
Expand Down