Skip to content

dump-c: fix output of _Bool-typed constants #5867

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 3 commits into from
Mar 2, 2021

Conversation

tautschnig
Copy link
Collaborator

Only __CPROVER_bool-typed constants can be used with exprt::is_true.
exprt::is_one's documentation promised that ID_c_bool was supported,
which wasn't actually the case. This commit fixes this and makes use of
is_one to fix the bug in dump-c.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #5867 (6779f39) into develop (42896e7) will decrease coverage by 0.00%.
The diff coverage is 82.35%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5867      +/-   ##
===========================================
- Coverage    72.90%   72.90%   -0.01%     
===========================================
  Files         1423     1425       +2     
  Lines       154159   154282     +123     
===========================================
+ Hits        112397   112485      +88     
- Misses       41762    41797      +35     
Impacted Files Coverage Δ
...yses/variable-sensitivity/abstract_environment.cpp 87.42% <ø> (ø)
...ble-sensitivity/constant_pointer_abstract_object.h 100.00% <ø> (ø)
...sensitivity/variable_sensitivity_configuration.cpp 70.37% <0.00%> (ø)
...e-sensitivity/variable_sensitivity_configuration.h 100.00% <ø> (ø)
...riable-sensitivity/variable_sensitivity_domain.cpp 87.11% <ø> (ø)
...-sensitivity/variable_sensitivity_object_factory.h 100.00% <ø> (ø)
src/goto-instrument/dump_c_class.h 100.00% <ø> (ø)
src/goto-instrument/goto_program2code.cpp 67.88% <ø> (-0.19%) ⬇️
src/util/simplify_expr_class.h 100.00% <ø> (ø)
src/goto-instrument/dump_c.cpp 79.59% <61.53%> (-0.39%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf88f82...6779f39. Read the comment docs.

irep
--
Dump-c previously always generated 0 for _Bool or __CPROVER_bool-typed
constants. This test ensures that the value "1" is correctly generated.

Choose a reason for hiding this comment

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

I don't understand how this test tests this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah... I'm not seeing it either. Not quite sure where the irep is coming from.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test description expanded: the previous (buggy) output made dump-c produce v = 0 instead of v = 1.

@@ -1521,22 +1521,48 @@ void dump_ct::cleanup_type(typet &type)
!type.get(ID_tag).empty());
}

static expr2c_configurationt expr2c_configuration()
{
static expr2c_configurationt configuration{

Choose a reason for hiding this comment

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

IMHO would be better written as a series of assignments, then you don't need the comments.

@@ -156,7 +152,7 @@ class dump_ct
symbol_tablet copied_symbol_table;
const namespacet ns;
const dump_c_configurationt dump_c_config;
std::unique_ptr<languaget> language;
const irep_idt mode;

Choose a reason for hiding this comment

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

This change should be a separate commit with an explanation for why it's done. It's not obvious to me that this is an improvement, and in any case it doesn't seem to be directly related to fixing anything with the output of booleans? Not saying I'm against this, just that the commit should do a better job of explaining it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Broken out into a second commit.

irep
--
Dump-c previously always generated 0 for _Bool or __CPROVER_bool-typed
constants. This test ensures that the value "1" is correctly generated.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah... I'm not seeing it either. Not quite sure where the irep is coming from.

@@ -526,7 +526,7 @@ void dump_ct::convert_compound(
if(t.get_width()<=config.ansi_c.long_long_int_width)
struct_body << "long long int " << comp_name
<< " : " << t.get_width();
else if(language->id()=="cpp")
else if(mode == ID_cpp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't seem to correspond with the PR message. I'm fine with them going in as a minor fix but just wanted to flag it in case it was a mistake.

@tautschnig tautschnig force-pushed the dump-c-bool-constant branch 2 times, most recently from 9c881b0 to 167877a Compare March 1, 2021 13:38
@tautschnig tautschnig self-assigned this Mar 1, 2021
@tautschnig tautschnig force-pushed the dump-c-bool-constant branch from 167877a to d95a0d0 Compare March 1, 2021 16:49
Only __CPROVER_bool-typed constants can be used with exprt::is_true.
exprt::is_one's documentation promised that ID_c_bool was supported,
which wasn't actually the case. This commit fixes this and makes use of
is_one to fix the bug in dump-c.
This avoids working around expr2c internals.
@tautschnig tautschnig force-pushed the dump-c-bool-constant branch from d95a0d0 to 1828d43 Compare March 2, 2021 15:55
The CSmith test generated with random seed 1614606277 demonstrated that
dump-c's handling still didn't cover all cases of byte_update expressions
introduced by the C front-end, specifically missing the case where a struct was
part of the union.
@tautschnig tautschnig merged commit 7f998c4 into diffblue:develop Mar 2, 2021
@tautschnig tautschnig deleted the dump-c-bool-constant branch March 2, 2021 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants