Skip to content

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

Conversation

hannes-steffenhagen-diffblue
Copy link
Contributor

The width of a bitfield is indicated with ID_width. Old version of type2name was using ID_size instead, which (silently) threw away the information about the width of a bitfield in the pretty printed type.

As a side note, I'm not sure it's such a good idea for the get* type functions to fail silently.

@martin-cs
Copy link
Collaborator

Fix looks good; any chance of a regression test to go with it? Preferably the one / a version of the one submitted in the original ticket.

@tautschnig
Copy link
Collaborator

I might be responsible for a some of this code. May I ask for a slightly bigger refactoring to use pointer_offset_bits instead? All those get_string calls should be dropped from that code; the width of ID_pointer should now also be considered.

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@tautschnig I'm not sure how you'd want to use pointer_offset_bits here. Also, what would you want to replace the get_string calls with?

@tautschnig
Copy link
Collaborator

@tautschnig I'm not sure how you'd want to use pointer_offset_bits here. Also, what would you want to replace the get_string calls with?

pointer_offset_bits will compute the bit-width of the type, and could/should be used instead of get_string(ID_width); the resulting mp_integer then needs to be turned into a string.

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@martin-cs I didn't find a test category that really fit for the test I was doing (though if there is one I'll happy to change this), so I made my own

@tautschnig I'm not entirely sure if I understood you correctly, is this what you had in mind?

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the goto-analyzer-develop_fix-bitfield branch 2 times, most recently from fc95904 to 2b424a1 Compare December 21, 2017 14:54
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all this additional work! Some more fixes are necessary, though.

@@ -10,6 +10,7 @@ DIRS = ansi-c \
goto-instrument \
goto-instrument-typedef \
test-script \
ansi-c-typename \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just add it to the goto-instrument directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

mp_integer bits = pointer_offset_bits(type, ns);
CHECK_RETURN(bits != -1);
return integer2string(bits);
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a strong reason not to use a function at file scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. I can do that if you prefer; I just put it in the function scope because I wasn't expecting to use it outside of the function and I don't need to pass parameters this way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasons for preferring the file-scoped function: 1) Consistency: we don't do it elsewhere. 2) I'm not sure how well doxygen can cope with it. 3) The function calls do not make clear what is captured, thus making the code harder to read.

None of this is a blocker, but readability is a very important aspect.

@@ -168,7 +177,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().id());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that would yield "symbol". Use id2string(t.size().get(ID_identifier))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -202,7 +211,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 != ID_nil);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil would actually be a valid name! component_name.empty() would be the error you are looking for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the goto-analyzer-develop_fix-bitfield branch from 2b424a1 to 06a353a Compare December 22, 2017 11:44
--

Checks that type2name generates the right names for structs containing bitfields,
in particular including the width of bitfield fields.
Copy link
Collaborator

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

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

(reminder: both AppVeyor and travis report failures for known issues that are unrelated to this PR)

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but could you just add the missing new-line, then I'll merge.

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the goto-analyzer-develop_fix-bitfield branch from 06a353a to defda7b Compare January 3, 2018 10:25
@chrisr-diffblue chrisr-diffblue merged commit 3bdabf2 into diffblue:goto-analyzer-develop Jan 3, 2018
@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue deleted the goto-analyzer-develop_fix-bitfield branch January 4, 2018 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants