-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7535 from peterschrammel/shadow-memory-basic2
Gather shadow memory fields
- Loading branch information
Showing
11 changed files
with
187 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void bad_declaration1() | ||
{ | ||
__CPROVER_field_decl_local("field1", (int)0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
void bad_declaration2() | ||
{ | ||
struct STRUCT | ||
{ | ||
char x; | ||
} s; | ||
__CPROVER_field_decl_global("field2", s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
void good_declarations() | ||
{ | ||
__CPROVER_field_decl_local("field1", (_Bool)0); | ||
__CPROVER_field_decl_global("field2", (unsigned __CPROVER_bitvector[6])0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
bad1.c | ||
--function bad_declaration1 --verbosity 10 | ||
^EXIT=6$ | ||
^SIGNAL=0$ | ||
^A shadow memory field must not be larger than 8 bits. | ||
-- | ||
-- | ||
Test that a shadow memory declaration of a too large type is rejected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
bad2.c | ||
--function bad_declaration2 --verbosity 10 | ||
^EXIT=6$ | ||
^SIGNAL=0$ | ||
^A shadow memory field must be of a bitvector type. | ||
-- | ||
-- | ||
Test that a shadow memory declaration of a non-bitvector type is rejected. |
12 changes: 12 additions & 0 deletions
12
regression/cbmc-shadow-memory/declarations1/test_good.desc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
good.c | ||
--function good_declarations --verbosity 10 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
^Shadow memory: declare local field field1 of type c_bool\[8\] | ||
^Shadow memory: declare global field field2 of type unsignedbv\[6\] | ||
-- | ||
^A shadow memory field must | ||
-- | ||
Test that shadow memory declarations are correctly gathered. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*******************************************************************\ | ||
Module: Symex Shadow Memory Instrumentation | ||
Author: Peter Schrammel | ||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Symex Shadow Memory Instrumentation Utilities | ||
|
||
#include "shadow_memory_util.h" | ||
|
||
#include <util/invariant.h> | ||
#include <util/pointer_expr.h> | ||
#include <util/std_expr.h> | ||
|
||
irep_idt extract_field_name(const exprt &string_expr) | ||
{ | ||
if(string_expr.id() == ID_typecast) | ||
return extract_field_name(to_typecast_expr(string_expr).op()); | ||
else if(string_expr.id() == ID_address_of) | ||
return extract_field_name(to_address_of_expr(string_expr).object()); | ||
else if(string_expr.id() == ID_index) | ||
return extract_field_name(to_index_expr(string_expr).array()); | ||
else if(string_expr.id() == ID_string_constant) | ||
{ | ||
return string_expr.get(ID_value); | ||
} | ||
else | ||
UNREACHABLE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*******************************************************************\ | ||
Module: Symex Shadow Memory Instrumentation | ||
Author: Peter Schrammel | ||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Symex Shadow Memory Instrumentation Utilities | ||
|
||
#ifndef CPROVER_GOTO_SYMEX_SHADOW_MEMORY_UTIL_H | ||
#define CPROVER_GOTO_SYMEX_SHADOW_MEMORY_UTIL_H | ||
|
||
#include <util/irep.h> | ||
|
||
class exprt; | ||
|
||
/// Extracts the field name identifier from a string expression, | ||
/// e.g. as passed as argument to a __CPROVER_field_decl_local call. | ||
/// \param string_expr The string argument expression | ||
/// \return The identifier denoted by the string argument expression | ||
irep_idt extract_field_name(const exprt &string_expr); | ||
|
||
#endif // CPROVER_GOTO_SYMEX_SHADOW_MEMORY_STATE_H |