-
Notifications
You must be signed in to change notification settings - Fork 276
Fixes use of wrong identifier when pretty printing bitfield types #1676
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
chrisr-diffblue
merged 3 commits into
diffblue:goto-analyzer-develop
from
hannes-steffenhagen-diffblue:goto-analyzer-develop_fix-bitfield
Jan 3, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
cb04798
Fixes use of wrong identifier when pretty printing bitfield types
hannes-steffenhagen-diffblue bacb1d5
Adds regression test for bitfield naming bug
hannes-steffenhagen-diffblue defda7b
Uses alternatives to get_string in type2name when possible
hannes-steffenhagen-diffblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
typedef struct { | ||
unsigned char b11 : 1; | ||
unsigned char b22 : 1; | ||
unsigned char b34 : 2; | ||
unsigned char b58 : 4; | ||
} bf_t; | ||
|
||
typedef union { | ||
unsigned char val; | ||
bf_t bf; | ||
} union_bf_t; | ||
|
||
int main(void) | ||
{ | ||
union_bf_t bf; | ||
bf.bf.b11 = 1; | ||
return 0; | ||
} |
This file contains hidden or 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,15 @@ | ||
CORE | ||
main.c | ||
--show-goto-functions --json-ui | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
BF1\{U8\}\$U8\$\'b11\' | ||
BF1\{U8\}\$U8\$\'b22\' | ||
BF2\{U8\}\$U8\$\'b34\' | ||
BF4\{U8\}\$U8\$\'b58\' | ||
-- | ||
-- | ||
|
||
Checks that type2name generates the right names for structs containing bitfields, | ||
in particular including the width of bitfield fields. | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -14,6 +14,8 @@ Author: Daniel Kroening, [email protected] | |
#include <util/namespace.h> | ||
#include <util/symbol.h> | ||
#include <util/symbol_table.h> | ||
#include <util/pointer_offset_size.h> | ||
#include <util/invariant.h> | ||
|
||
#include "type2name.h" | ||
|
||
|
@@ -81,6 +83,15 @@ static std::string type2name_symbol( | |
return result; | ||
} | ||
|
||
static std::string pointer_offset_bits_as_string( | ||
const typet &type, | ||
const namespacet &ns) | ||
{ | ||
mp_integer bits = pointer_offset_bits(type, ns); | ||
CHECK_RETURN(bits != -1); | ||
return integer2string(bits); | ||
} | ||
|
||
static bool parent_is_sym_check=false; | ||
static std::string type2name( | ||
const typet &type, | ||
|
@@ -115,9 +126,9 @@ static std::string type2name( | |
else if(type.id()==ID_empty) | ||
result+='V'; | ||
else if(type.id()==ID_signedbv) | ||
result+="S" + type.get_string(ID_width); | ||
result+="S" + pointer_offset_bits_as_string(type, ns); | ||
else if(type.id()==ID_unsignedbv) | ||
result+="U" + type.get_string(ID_width); | ||
result+="U" + pointer_offset_bits_as_string(type, ns); | ||
else if(type.id()==ID_bool || | ||
type.id()==ID_c_bool) | ||
result+='B'; | ||
|
@@ -128,13 +139,13 @@ static std::string type2name( | |
else if(type.id()==ID_complex) | ||
result+='C'; | ||
else if(type.id()==ID_floatbv) | ||
result+="F" + type.get_string(ID_width); | ||
result+="F" + pointer_offset_bits_as_string(type, ns); | ||
else if(type.id()==ID_fixedbv) | ||
result+="X" + type.get_string(ID_width); | ||
result+="X" + pointer_offset_bits_as_string(type, ns); | ||
else if(type.id()==ID_natural) | ||
result+='N'; | ||
else if(type.id()==ID_pointer) | ||
result+='*'; | ||
result+="*" + pointer_offset_bits_as_string(type, ns); | ||
else if(type.id()==ID_reference) | ||
result+='&'; | ||
else if(type.id()==ID_code) | ||
|
@@ -168,7 +179,7 @@ static std::string type2name( | |
const array_typet &t=to_array_type(type); | ||
mp_integer size; | ||
if(t.size().id()==ID_symbol) | ||
result+="ARR"+t.size().get_string(ID_identifier); | ||
result+="ARR"+id2string(t.size().get(ID_identifier)); | ||
else if(to_integer(t.size(), size)) | ||
result+="ARR?"; | ||
else | ||
|
@@ -202,7 +213,9 @@ static std::string type2name( | |
if(it!=components.begin()) | ||
result+='|'; | ||
result+=type2name(it->type(), ns, symbol_number); | ||
result+="'"+it->get_string(ID_name)+"'"; | ||
irep_idt component_name = it->get_name(); | ||
CHECK_RETURN(!component_name.empty()); | ||
result+="'"+id2string(component_name)+"'"; | ||
} | ||
result+=']'; | ||
} | ||
|
@@ -230,7 +243,7 @@ static std::string type2name( | |
else if(type.id()==ID_incomplete_c_enum) | ||
result +="EN?"; | ||
else if(type.id()==ID_c_bit_field) | ||
result+="BF"+type.get_string(ID_size); | ||
result+="BF"+pointer_offset_bits_as_string(type, ns); | ||
else if(type.id()==ID_vector) | ||
result+="VEC"+type.get_string(ID_size); | ||
else | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit pick: no new line at end-of-file