Skip to content

Wrong --conversion-check in cast from double to unsigned #8131

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

Closed
cesaro opened this issue Dec 20, 2023 · 0 comments · Fixed by #8157
Closed

Wrong --conversion-check in cast from double to unsigned #8131

cesaro opened this issue Dec 20, 2023 · 0 comments · Fixed by #8157

Comments

@cesaro
Copy link
Contributor

cesaro commented Dec 20, 2023

The below program

int main() {
  unsigned u = 0xffffffffu;

  // since the double type seems to be implemented with a IEEE 754 binary64
  // format in CBMC, which has 53 bits of mantissa, double has enough bits to
  // represent the exact value of u, use, e.g., http://weitz.de/ieee/ to check;
  // therefore, C17, section 6.3.1.4, paragraph 2 says that this is
  // defined behavior and d should store the exact value that u stores
  double d = u;

  // defined behavior behavior as well, by C17 section 6.3.1.4, paragraph 1,
  // because the 'unsigned' type can represent the value; however,
  // cbmc --conversion-check complains
  u = (unsigned) d;

  return 0;
}

doesn't have undefined behavior in the double-to-unsigned conversion, according to C17, section 6.3.1.4, paragraph 1, but

cbmc --conversion-check main.c

in Linux, using latest develop, complains about an arithmetic overflow.

tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 11, 2024
We use less-than in the comparison, so make the bound one larger than
the largest representable value (as we do in the other cases of
float-to-signed/unsigned conversion checks).

Fixes: diffblue#8131
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants