Skip to content

Fix narrowing conversions seen by test-gen#3900

Merged
LAJW merged 2 commits intodiffblue:developfrom
LAJW:lajw/narrow
Jan 24, 2019
Merged

Fix narrowing conversions seen by test-gen#3900
LAJW merged 2 commits intodiffblue:developfrom
LAJW:lajw/narrow

Conversation

@LAJW
Copy link
Contributor

@LAJW LAJW commented Jan 23, 2019

I want to enable conversion warnings in test-gen. Unfortunately, I can't because CBMC uses unchecked conversions in its headers. Because there were only so few, rather than guard CBMC headers, I decided to just fix them.

I'm also including a narrow_cast and narrow (inspired by Guidelines Support Library) with this to mark conversion warnings as such.

Rationale:

@tautschnig
Copy link
Collaborator

One day I'll actually be getting PRs reviewed and duplicate work will no longer be happening... See #2551, which is factored out from #2310. Anyway, the approach taken here is cleaner. I'll review and will then approve...

Copy link
Contributor

@hannes-steffenhagen-diffblue hannes-steffenhagen-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 reasonable to me, copyright needs to be sorted out though. Also FWIW I think it'd make more sense to use narrow for all of these cases, I don't think any of them are meant to over/underflow

@@ -0,0 +1,34 @@
// Copyright 2019 Diffblue Limited. All Rights Reserved.
Copy link
Contributor

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue Jan 23, 2019

Choose a reason for hiding this comment

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

You need to use the normal cbmc copyright header here instead. In particular this shouldn't be all rights reserved

/// Alias for static_cast intended to be used for numeric casting
/// Rationale: Easier to grep than static_cast
template <typename output_type, typename input_type>
output_type narrow_cast(input_type value)

Choose a reason for hiding this comment

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

If this is derived from Microsoft GSL this might need an appropriate copyright notice to that effect

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 necessary, I wrote it from scratch in test-gen.

static_assert(
std::is_arithmetic<input_type>::value &&
std::is_arithmetic<output_type>::value,
"numeric_cast is intended only for numeric conversions");

Choose a reason for hiding this comment

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

s/numeric_cast/narrow_cast?

@@ -0,0 +1,34 @@
// Copyright 2019 Diffblue Limited. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sync within Diffblue whether that's a copyright mark to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copyright updated.

static_assert(
std::is_arithmetic<input_type>::value &&
std::is_arithmetic<output_type>::value,
"numeric_cast is intended only for numeric conversions");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The function is called narrow_cast, but it does make we wonder whether we really need both narrow_cast and numeric_cast(_v)?

Choose a reason for hiding this comment

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

Wasn't numeric cast for expr -> mp_integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

narrow_cast is intended only to suppress compiler warnings. It isn't meant to handle errors. It works exactly like static_cast. But it's easier to grep.

@LAJW
Copy link
Contributor Author

LAJW commented Jan 23, 2019

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

🚫
This PR failed Diffblue compatibility checks (cbmc commit: b158de9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98356611
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

🚫
This PR failed Diffblue compatibility checks (cbmc commit: b648a98).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98450723
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

@LAJW LAJW merged commit bed39f8 into diffblue:develop Jan 24, 2019
@LAJW LAJW deleted the lajw/narrow branch January 24, 2019 13:18
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.

5 participants